CVE-2021-3517: Nokogiri Nokogiri Contains Libxml Out-of-bounds Write Vulnerability

HIGH
Advisory Identifier: GHSA-jw9f-hh49-cvp9
CVSS 8.6
CWE-787
Published
Advisory Summary

CVE-2021-3517 is a HIGH (CVSS 8.6) nokogiri contains libxml out-of-bounds write vulnerability (CWE-787: Out-of-bounds Write) affecting Nokogiri libraries in the RubyGems ecosystem. The issue involves nokogiri contains libxml out-of-bounds write vulnerability. Remediation is available by upgrading affected packages to version 1.11.4.

CVE-2021-3517 at a Glance

CVE Identifier CVE-2021-3517
GHSA Identifier GHSA-jw9f-hh49-cvp9
Severity HIGH
CVSS v3.1 Base Score 8.6
CWE Classification CWE-787: Out-of-bounds Write
Affected Product Nokogiri
Package Ecosystem RubyGems
Published Date
Last Updated

Security Impact

CVSS: 8.6

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:L/A:H).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality Low (C:L)
Integrity Low (I:L)
Availability High (A:H)

How to Fix CVE-2021-3517

To remediate this vulnerability, upgrade all affected Nokogiri dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

nokogiri fixed: 1.11.4
Upgrade nokogiri to 1.11.4
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

inspect dependencies for nokogiri

How to Check if You Are Affected

To determine whether your application is affected by CVE-2021-3517, inspect your project dependencies for Nokogiri:

inspect dependencies for nokogiri

Analyze the terminal output to locate any version of Nokogiri in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 1.11.4), your application is affected.

Note: Verify declared build manifests and deployed runtime container environments.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-787: Out-of-bounds Write, where the product writes data past the end, or before the beginning, of the intended buffer. In Nokogiri, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

There is a flaw in the xml entity encoding functionality of libxml2 in versions before 2.9.11. An attacker who is able to supply a crafted file to be processed by an application linked with the affected functionality of libxml2 could trigger an out-of-bounds read. The most likely impact of this flaw is to application availability, with some potential impact to confidentiality and integrity if an attacker is able to use memory information to further exploit the application. Nokogiri prior to version 1.11.4 used a vulnerable version of libxml2. Nokogiri 1.11.4 updated libxml2 to version 2.9.11 to address this and other vulnerabilities in libxml2.

CVE-2021-3517 Affected Nokogiri Versions

1 component(s)
Fixed Versions:
1.11.4
Product / Package Ecosystem Affected Versions Fixed Version
nokogiri
RubyGems
< 1.11.4
1.11.4

References

NVD — CVE-2021-3517 NVD
https://nvd.nist.gov/vuln/detail/CVE-2021-3517
Nokogiri Source Repository REPOSITORY
https://github.com/sparklemotion/nokogiri/issues/2233
Nokogiri Source Repository REPOSITORY
https://github.com/sparklemotion/nokogiri/issues/2274
Nokogiri Security Information SECURITY
https://www.oracle.com/security-alerts/cpuoct2021.html
Nokogiri Security Information SECURITY
https://www.oracle.com/security-alerts/cpujul2022.html
Nokogiri Security Information SECURITY
https://www.oracle.com/security-alerts/cpujan2022.html
Nokogiri Security Information SECURITY
https://www.oracle.com/security-alerts/cpuapr2022.html
Nokogiri Security Information SECURITY
https://security.netapp.com/advisory/ntap-20211022-0004
Nokogiri Security Information SECURITY
https://security.netapp.com/advisory/ntap-20210625-0002
Nokogiri Security Information SECURITY
https://security.gentoo.org/glsa/202107-05
lists.fedoraproject.org/archives/list/packa... WEB
https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/QVM4UJ3376I6ZVOYMHBNX4GY3NIV52WV
lists.fedoraproject.org/archives/list/packa... WEB
https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/BZOMV5J4PMZAORVT64BKLV6YIZAFDGX6
lists.debian.org/debian-lts-announce... WEB
https://lists.debian.org/debian-lts-announce/2021/05/msg00008.html
gitlab.gnome.org/gnome/libxml2/-/com... WEB
https://gitlab.gnome.org/GNOME/libxml2/-/commit/8598060bacada41a0eb09d95c97744ff4e428f8e
Nokogiri Source Repository REPOSITORY
https://github.com/sparklemotion/nokogiri/blob/7c19ef5cc6b7c5c36827dd5495f857c6877ec8cf/CHANGELOG.md?plain=1#L579
Nokogiri Source Repository REPOSITORY
https://github.com/sparklemotion/nokogiri
Nokogiri Source Repository REPOSITORY
https://github.com/rubysec/ruby-advisory-db/blob/master/gems/nokogiri/CVE-2021-3517.yml
bugzilla.redhat.com/show_bug.cgi WEB
https://bugzilla.redhat.com/show_bug.cgi?id=1954232

Frequently Asked Questions

What is CVE-2021-3517?
CVE-2021-3517 is a security vulnerability in Nokogiri involving Nokogiri contains libxml Out-of-bounds Write vulnerability under CWE-787: Out-of-bounds Write.
Which Nokogiri versions are affected?
Affected versions include releases prior to 1.11.4 across affected packages: nokogiri.
What version fixes CVE-2021-3517?
Upgrading to 1.11.4 (or the latest patched release for your respective branch) resolves the vulnerability.
Is nokogiri affected?
Yes, nokogiri is affected in releases prior to 1.11.4. Upgrade your dependency to 1.11.4 or later.
What is the CVSS score of CVE-2021-3517?
CVE-2021-3517 has a CVSS v3.1 base score of 8.6 (HIGH) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:L/A:H.
What CWE is associated with CVE-2021-3517?
CVE-2021-3517 is classified under CWE-787: Out-of-bounds Write (The product writes data past the end, or before the beginning, of the intended buffer.).
How can I check RubyGems dependencies for CVE-2021-3517?
Run the dependency tree command: 'inspect dependencies for nokogiri'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-jw9f-hh49-cvp9",
  "modified" : "2023-08-28T13:57:20Z",
  "published" : "2022-05-24T19:02:48Z",
  "aliases" : [ "CVE-2021-3517" ],
  "summary" : "Nokogiri contains libxml Out-of-bounds Write vulnerability",
  "details" : "There is a flaw in the xml entity encoding functionality of libxml2 in versions before 2.9.11. An attacker who is able to supply a crafted file to be processed by an application linked with the affected functionality of libxml2 could trigger an out-of-bounds read. The most likely impact of this flaw is to application availability, with some potential impact to confidentiality and integrity if an attacker is able to use memory information to further exploit the application.\n\nNokogiri prior to version 1.11.4 used a vulnerable version of libxml2. Nokogiri 1.11.4 updated libxml2 to version 2.9.11 to address this and other vulnerabilities in libxml2.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:L/A:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "RubyGems",
      "name" : "nokogiri"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "1.11.4"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2021-3517"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/sparklemotion/nokogiri/issues/2233"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/sparklemotion/nokogiri/issues/2274"
  }, {
    "type" : "WEB",
    "url" : "https://www.oracle.com/security-alerts/cpuoct2021.html"
  }, {
    "type" : "WEB",
    "url" : "https://www.oracle.com/security-alerts/cpujul2022.html"
  }, {
    "type" : "WEB",
    "url" : "https://www.oracle.com/security-alerts/cpujan2022.html"
  }, {
    "type" : "WEB",
    "url" : "https://www.oracle.com/security-alerts/cpuapr2022.html"
  }, {
    "type" : "WEB",
    "url" : "https://security.netapp.com/advisory/ntap-20211022-0004"
  }, {
    "type" : "WEB",
    "url" : "https://security.netapp.com/advisory/ntap-20210625-0002"
  }, {
    "type" : "WEB",
    "url" : "https://security.gentoo.org/glsa/202107-05"
  }, {
    "type" : "WEB",
    "url" : "https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/QVM4UJ3376I6ZVOYMHBNX4GY3NIV52WV"
  }, {
    "type" : "WEB",
    "url" : "https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/BZOMV5J4PMZAORVT64BKLV6YIZAFDGX6"
  }, {
    "type" : "WEB",
    "url" : "https://lists.debian.org/debian-lts-announce/2021/05/msg00008.html"
  }, {
    "type" : "WEB",
    "url" : "https://gitlab.gnome.org/GNOME/libxml2/-/commit/8598060bacada41a0eb09d95c97744ff4e428f8e"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/sparklemotion/nokogiri/blob/7c19ef5cc6b7c5c36827dd5495f857c6877ec8cf/CHANGELOG.md?plain=1#L579"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/sparklemotion/nokogiri"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/rubysec/ruby-advisory-db/blob/master/gems/nokogiri/CVE-2021-3517.yml"
  }, {
    "type" : "WEB",
    "url" : "https://bugzilla.redhat.com/show_bug.cgi?id=1954232"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-787" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2023-03-08T20:01:46Z",
    "nvd_published_at" : "2021-05-19T14:15:00Z"
  }
}