CVE-2021-3518: Nokogiri Nokogiri Implements Libxml2 Version Vulnerable Vulnerability

HIGH
Advisory Identifier: GHSA-v4f8-2847-rwm7
CVSS 8.8
CWE-416
Published
Advisory Summary

CVE-2021-3518 is a HIGH (CVSS 8.8) nokogiri implements libxml2 version vulnerable vulnerability (CWE-416: Use After Free) affecting Nokogiri libraries in the RubyGems ecosystem. The issue involves nokogiri implements libxml2 version vulnerable to use-after-free. Remediation is available by upgrading affected packages to version 1.11.4.

CVE-2021-3518 at a Glance

CVE Identifier CVE-2021-3518
GHSA Identifier GHSA-v4f8-2847-rwm7
Severity HIGH
CVSS v3.1 Base Score 8.8
CWE Classification CWE-416: Use After Free
Affected Product Nokogiri
Package Ecosystem RubyGems
Published Date
Last Updated

Security Impact

CVSS: 8.8

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:R/S:U/C:H/I:H/A:H).

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

How to Fix CVE-2021-3518

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-3518, 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-416: Use After Free, where the product reuses or references memory after it has been freed. at some point afterward, the memory may be allocated again and saved in another pointer, while the original pointer references a location somewhere within the new allocation. any operations using the original pointer are no longer valid because the memory "belongs" to the code that operates on the new pointer. 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's a flaw in libxml2 in versions before 2.9.11. An attacker who is able to submit a crafted file to be processed by an application linked with libxml2 could trigger a use-after-free. The greatest impact from this flaw is to confidentiality, integrity, and availability.

CVE-2021-3518 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-3518 NVD
https://nvd.nist.gov/vuln/detail/CVE-2021-3518
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/cpuapr2022.html
support.apple.com/kb/ht212605 WEB
https://support.apple.com/kb/HT212605
support.apple.com/kb/ht212604 WEB
https://support.apple.com/kb/HT212604
support.apple.com/kb/ht212602 WEB
https://support.apple.com/kb/HT212602
support.apple.com/kb/ht212601 WEB
https://support.apple.com/kb/HT212601
Nokogiri Security Information SECURITY
https://security.netapp.com/advisory/ntap-20210625-0002
Nokogiri Security Information SECURITY
https://security.gentoo.org/glsa/202107-05
Nokogiri Security Information SECURITY
https://nokogiri.org/CHANGELOG.html#1114-2021-05-14
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
lists.apache.org/thread.html/rf4c027... WEB
https://lists.apache.org/thread.html/rf4c02775860db415b4955778a131c2795223f61cb8c6a450893651e4@%3Cissues.bookkeeper.apache.org%3E
lists.apache.org/thread.html/r58af02... WEB
https://lists.apache.org/thread.html/r58af02e294bd07f487e2c64ffc0a29b837db5600e33b6e698b9d696b@%3Cissues.bookkeeper.apache.org%3E
Nokogiri Source Repository REPOSITORY
https://github.com/sparklemotion/nokogiri/blob/2edbbef95f1dc12c1ddc5ebda71b9159026245fe/CHANGELOG.md?plain=1#L722
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-3518.yml
bugzilla.redhat.com/show_bug.cgi WEB
https://bugzilla.redhat.com/show_bug.cgi?id=1954242
seclists.org/fulldisclosure/2021... WEB
http://seclists.org/fulldisclosure/2021/Jul/54
seclists.org/fulldisclosure/2021... WEB
http://seclists.org/fulldisclosure/2021/Jul/55
seclists.org/fulldisclosure/2021... WEB
http://seclists.org/fulldisclosure/2021/Jul/58
seclists.org/fulldisclosure/2021... WEB
http://seclists.org/fulldisclosure/2021/Jul/59

Frequently Asked Questions

What is CVE-2021-3518?
CVE-2021-3518 is a security vulnerability in Nokogiri involving Nokogiri Implements libxml2 version vulnerable to use-after-free under CWE-416: Use After Free.
Which Nokogiri versions are affected?
Affected versions include releases prior to 1.11.4 across affected packages: nokogiri.
What version fixes CVE-2021-3518?
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-3518?
CVE-2021-3518 has a CVSS v3.1 base score of 8.8 (HIGH) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H.
What CWE is associated with CVE-2021-3518?
CVE-2021-3518 is classified under CWE-416: Use After Free (The product reuses or references memory after it has been freed. At some point afterward, the memory may be allocated again and saved in another pointer, while the original pointer references a location somewhere within the new allocation. Any operations using the original pointer are no longer valid because the memory "belongs" to the code that operates on the new pointer.).
How can I check RubyGems dependencies for CVE-2021-3518?
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-v4f8-2847-rwm7",
  "modified" : "2023-07-10T13:02:34Z",
  "published" : "2022-05-24T19:02:44Z",
  "aliases" : [ "CVE-2021-3518" ],
  "summary" : "Nokogiri Implements libxml2 version vulnerable to use-after-free",
  "details" : "There's a flaw in libxml2 in versions before 2.9.11. An attacker who is able to submit a crafted file to be processed by an application linked with libxml2 could trigger a use-after-free. The greatest impact from this flaw is to confidentiality, integrity, and availability.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/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-3518"
  }, {
    "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/cpuapr2022.html"
  }, {
    "type" : "WEB",
    "url" : "https://support.apple.com/kb/HT212605"
  }, {
    "type" : "WEB",
    "url" : "https://support.apple.com/kb/HT212604"
  }, {
    "type" : "WEB",
    "url" : "https://support.apple.com/kb/HT212602"
  }, {
    "type" : "WEB",
    "url" : "https://support.apple.com/kb/HT212601"
  }, {
    "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://nokogiri.org/CHANGELOG.html#1114-2021-05-14"
  }, {
    "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://lists.apache.org/thread.html/rf4c02775860db415b4955778a131c2795223f61cb8c6a450893651e4@%3Cissues.bookkeeper.apache.org%3E"
  }, {
    "type" : "WEB",
    "url" : "https://lists.apache.org/thread.html/r58af02e294bd07f487e2c64ffc0a29b837db5600e33b6e698b9d696b@%3Cissues.bookkeeper.apache.org%3E"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/sparklemotion/nokogiri/blob/2edbbef95f1dc12c1ddc5ebda71b9159026245fe/CHANGELOG.md?plain=1#L722"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/sparklemotion/nokogiri"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/rubysec/ruby-advisory-db/blob/master/gems/nokogiri/CVE-2021-3518.yml"
  }, {
    "type" : "WEB",
    "url" : "https://bugzilla.redhat.com/show_bug.cgi?id=1954242"
  }, {
    "type" : "WEB",
    "url" : "http://seclists.org/fulldisclosure/2021/Jul/54"
  }, {
    "type" : "WEB",
    "url" : "http://seclists.org/fulldisclosure/2021/Jul/55"
  }, {
    "type" : "WEB",
    "url" : "http://seclists.org/fulldisclosure/2021/Jul/58"
  }, {
    "type" : "WEB",
    "url" : "http://seclists.org/fulldisclosure/2021/Jul/59"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-416" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2023-07-05T21:16:34Z",
    "nvd_published_at" : "2021-05-18T12:15:00Z"
  }
}