# CVE-2018-16395: Ruby Openssl Allows Incorrect Value Comparison

> Flawed certificate comparison in Ruby's OpenSSL allows accepting illegitimate certificates, bypassing security checks for signing or encryption.

- **Severity:** Critical 9.8 (`CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H`)
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 16 Nov 2018
- **Updated:** 5 Aug 2024
- **Also known as:** ALPINE-CVE-2018-16395, CLEANSTART-2026-QW33820, GHSA-mmrq-6999-72v8, RHSA-2018:3738, RHSA-2019:1948, RHSA-2019:2565, UBUNTU-CVE-2018-16395

## What is CVE-2018-16395?

CVE-2018-16395 is a critical vulnerability in Canonical Ubuntu Linux, published on 16 Nov 2018. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official description

An issue was discovered in the OpenSSL library in Ruby before 2.3.8, 2.4.x before 2.4.5, 2.5.x before 2.5.2, and 2.6.x before 2.6.0-preview3. When two OpenSSL::X509::Name objects are compared using ==, depending on the ordering, non-equal objects may return true. When the first argument is one character longer than the second, or the second argument contains a character that is one less than a character in the same position of the first argument, the result of == will be true. This could be leveraged to create an illegitimate certificate that may be accepted as legitimate and then used in signing or encryption operations.

## Which versions are affected by CVE-2018-16395?

4 open source packages ship an affected version, including openssl. It affects 5 products.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `openssl` | RubyGems | All versions | 2.0.9 |
| `openssl` | RubyGems | All versions | 2.0.9 |
| `openssl` | RubyGems | From 2.1.0 | 2.1.2 |
| `openssl` | RubyGems | From 2.1.0 | 2.1.2 |
| `ruby` | Red Hat:enterprise_linux:7::client | All versions | 0:2.0.0.648-34.el7_6 |
| `ruby-debuginfo` | Red Hat:enterprise_linux:7::client | All versions | 0:2.0.0.648-34.el7_6 |
| `ruby-devel` | Red Hat:enterprise_linux:7::client | All versions | 0:2.0.0.648-34.el7_6 |
| `ruby-doc` | Red Hat:enterprise_linux:7::client | All versions | 0:2.0.0.648-34.el7_6 |
| `ruby-irb` | Red Hat:enterprise_linux:7::client | All versions | 0:2.0.0.648-34.el7_6 |
| `ruby-libs` | Red Hat:enterprise_linux:7::client | All versions | 0:2.0.0.648-34.el7_6 |
| `ruby-tcltk` | Red Hat:enterprise_linux:7::client | All versions | 0:2.0.0.648-34.el7_6 |
| `rubygem-bigdecimal` | Red Hat:enterprise_linux:7::client | All versions | 0:1.2.0-34.el7_6 |
| `rubygem-io-console` | Red Hat:enterprise_linux:7::client | All versions | 0:0.4.2-34.el7_6 |
| `rubygem-json` | Red Hat:enterprise_linux:7::client | All versions | 0:1.7.7-34.el7_6 |
| `rubygem-minitest` | Red Hat:enterprise_linux:7::client | All versions | 0:4.3.2-34.el7_6 |
| `rubygem-psych` | Red Hat:enterprise_linux:7::client | All versions | 0:2.0.0-34.el7_6 |
| `rubygem-rake` | Red Hat:enterprise_linux:7::client | All versions | 0:0.9.6-34.el7_6 |
| `rubygem-rdoc` | Red Hat:enterprise_linux:7::client | All versions | 0:4.0.0-34.el7_6 |
| `rubygems` | Red Hat:enterprise_linux:7::client | All versions | 0:2.0.14.1-34.el7_6 |
| `rubygems-devel` | Red Hat:enterprise_linux:7::client | All versions | 0:2.0.14.1-34.el7_6 |
| `ruby` | Red Hat:enterprise_linux:7::computenode | All versions | 0:2.0.0.648-34.el7_6 |
| `ruby-debuginfo` | Red Hat:enterprise_linux:7::computenode | All versions | 0:2.0.0.648-34.el7_6 |
| `ruby-devel` | Red Hat:enterprise_linux:7::computenode | All versions | 0:2.0.0.648-34.el7_6 |
| `ruby-doc` | Red Hat:enterprise_linux:7::computenode | All versions | 0:2.0.0.648-34.el7_6 |
| `ruby-irb` | Red Hat:enterprise_linux:7::computenode | All versions | 0:2.0.0.648-34.el7_6 |
| `ruby-libs` | Red Hat:enterprise_linux:7::computenode | All versions | 0:2.0.0.648-34.el7_6 |
| `ruby-tcltk` | Red Hat:enterprise_linux:7::computenode | All versions | 0:2.0.0.648-34.el7_6 |
| `rubygem-bigdecimal` | Red Hat:enterprise_linux:7::computenode | All versions | 0:1.2.0-34.el7_6 |
| `rubygem-io-console` | Red Hat:enterprise_linux:7::computenode | All versions | 0:0.4.2-34.el7_6 |
| `rubygem-json` | Red Hat:enterprise_linux:7::computenode | All versions | 0:1.7.7-34.el7_6 |
| `rubygem-minitest` | Red Hat:enterprise_linux:7::computenode | All versions | 0:4.3.2-34.el7_6 |
| `rubygem-psych` | Red Hat:enterprise_linux:7::computenode | All versions | 0:2.0.0-34.el7_6 |
| `rubygem-rake` | Red Hat:enterprise_linux:7::computenode | All versions | 0:0.9.6-34.el7_6 |
| `rubygem-rdoc` | Red Hat:enterprise_linux:7::computenode | All versions | 0:4.0.0-34.el7_6 |
| `rubygems` | Red Hat:enterprise_linux:7::computenode | All versions | 0:2.0.14.1-34.el7_6 |
| `rubygems-devel` | Red Hat:enterprise_linux:7::computenode | All versions | 0:2.0.14.1-34.el7_6 |
| `ruby` | Red Hat:enterprise_linux:7::server | All versions | 0:2.0.0.648-34.el7_6 |
| `ruby-debuginfo` | Red Hat:enterprise_linux:7::server | All versions | 0:2.0.0.648-34.el7_6 |
| `ruby-devel` | Red Hat:enterprise_linux:7::server | All versions | 0:2.0.0.648-34.el7_6 |
| `ruby-doc` | Red Hat:enterprise_linux:7::server | All versions | 0:2.0.0.648-34.el7_6 |

Products: Canonical Ubuntu Linux, Debian Debian Linux, Redhat Enterprise Linux, Ruby-Lang Openssl, Ruby-Lang Ruby.

## How do I fix CVE-2018-16395?

Upgrade openssl to a fixed version for your release line: 2.0.9 or 2.1.2.

## Is CVE-2018-16395 being exploited?

There is no known exploitation of CVE-2018-16395 in the wild and no public exploit code.

## Other vulnerabilities in Canonical Ubuntu Linux

- [CVE-2020-11651](https://insights.sbomify.com/CVE-2020-11651/): SaltStack Salt Authentication Bypass (critical 9.8, exploited in the wild)
- [CVE-2020-7247](https://insights.sbomify.com/CVE-2020-7247/): OpenSMTPD Remote Code Execution (critical 9.8, exploited in the wild)
- [CVE-2019-16928](https://insights.sbomify.com/CVE-2019-16928/): Exim Out-of-bounds Write (critical 9.8, exploited in the wild)
- [CVE-2018-6789](https://insights.sbomify.com/CVE-2018-6789/): Exim Buffer Overflow (critical 9.8, exploited in the wild)
- [CVE-2015-2590](https://insights.sbomify.com/CVE-2015-2590/): Oracle Java SE and Java SE Embedded Remote Code Execution (critical 9.8, exploited in the wild)

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2018-16395 and fix it if it is affected.

What it is: CVE-2018-16395 is a critical vulnerability in Canonical Ubuntu Linux, published on 16 Nov 2018. An attacker can exploit it over the internet without logging in, with no action from the victim.
Exploitation: There is no known exploitation of CVE-2018-16395 in the wild and no public exploit code.

Affected packages and fixed versions:
- openssl (RubyGems): affected all versions; fixed in 2.0.9
- openssl (RubyGems): affected all versions; fixed in 2.0.9
- openssl (RubyGems): affected from 2.1.0; fixed in 2.1.2
- openssl (RubyGems): affected from 2.1.0; fixed in 2.1.2

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/CVE-2018-16395/ (Markdown: https://insights.sbomify.com/CVE-2018-16395/index.md)
```

## Sources

- CVE record: https://www.cve.org/CVERecord?id=CVE-2018-16395
- NVD: https://nvd.nist.gov/vuln/detail/CVE-2018-16395
- OSV: https://osv.dev/vulnerability/CVE-2018-16395

---
From sbomify Insights: https://insights.sbomify.com/CVE-2018-16395/
Summaries are generated and may contain mistakes; the official description above is the record.
