CVE-2016-4658: Nokogiri Nokogiri Does Not Forbid Namespace Vulnerability

CRITICAL
Advisory Identifier: GHSA-fr52-4hqw-p27f
CVSS 9.8
CWE-119
Published
Advisory Summary

CVE-2016-4658 is a CRITICAL (CVSS 9.8) nokogiri does not forbid namespace vulnerability (CWE-119: Improper Restriction of Operations within the Bounds of a Memory Buffer) affecting Nokogiri libraries in the RubyGems ecosystem. The issue involves nokogiri does not forbid namespace nodes in xpointer ranges. Remediation is available by upgrading affected packages to version 1.7.1.

CVE-2016-4658 at a Glance

CVE Identifier CVE-2016-4658
GHSA Identifier GHSA-fr52-4hqw-p27f
Severity CRITICAL
CVSS v3.1 Base Score 9.8
CWE Classification CWE-119: Improper Restriction of Operations within the Bounds of a Memory Buffer
Affected Product Nokogiri
Package Ecosystem RubyGems
Published Date
Last Updated

Security Impact

CVSS: 9.8

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.0/AV:N/AC:L/PR:N/UI:N/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 None (UI:N)
Scope Unchanged (S:U)
Confidentiality High (C:H)
Integrity High (I:H)
Availability High (A:H)

How to Fix CVE-2016-4658

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.7.1
Upgrade nokogiri to 1.7.1
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-2016-4658, 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.7.1), 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-119: Improper Restriction of Operations within the Bounds of a Memory Buffer, where the product performs operations on a memory buffer, but it reads from or writes to a memory location outside the buffer's intended boundary. this may result in read or write operations on unexpected memory locations that could be linked to other variables, data structures, or internal program data. 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

xpointer.c in libxml2 before 2.9.5 (as used in nokogiri before 1.7.1 amongst other products) does not forbid namespace nodes in XPointer ranges, which allows remote attackers to execute arbitrary code or cause a denial of service (use-after-free and memory corruption) via a crafted XML document.

CVE-2016-4658 Affected Nokogiri Versions

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

References

Frequently Asked Questions

What is CVE-2016-4658?
CVE-2016-4658 is a security vulnerability in Nokogiri involving Nokogiri does not forbid namespace nodes in XPointer ranges under CWE-119: Improper Restriction of Operations within the Bounds of a Memory Buffer.
Which Nokogiri versions are affected?
Affected versions include releases prior to 1.7.1 across affected packages: nokogiri.
What version fixes CVE-2016-4658?
Upgrading to 1.7.1 (or the latest patched release for your respective branch) resolves the vulnerability.
Is nokogiri affected?
Yes, nokogiri is affected in releases prior to 1.7.1. Upgrade your dependency to 1.7.1 or later.
What is the CVSS score of CVE-2016-4658?
CVE-2016-4658 has a CVSS v3.1 base score of 9.8 (CRITICAL) with vector string CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H.
What CWE is associated with CVE-2016-4658?
CVE-2016-4658 is classified under CWE-119: Improper Restriction of Operations within the Bounds of a Memory Buffer (The product performs operations on a memory buffer, but it reads from or writes to a memory location outside the buffer's intended boundary. This may result in read or write operations on unexpected memory locations that could be linked to other variables, data structures, or internal program data.).
How can I check RubyGems dependencies for CVE-2016-4658?
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-fr52-4hqw-p27f",
  "modified" : "2022-04-26T18:24:04Z",
  "published" : "2018-08-21T19:03:26Z",
  "aliases" : [ "CVE-2016-4658" ],
  "summary" : "Nokogiri does not forbid namespace nodes in XPointer ranges",
  "details" : "xpointer.c in libxml2 before 2.9.5 (as used in nokogiri before 1.7.1 amongst other products) does not forbid namespace nodes in XPointer ranges, which allows remote attackers to execute arbitrary code or cause a denial of service (use-after-free and memory corruption) via a crafted XML document.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "RubyGems",
      "name" : "nokogiri"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "1.7.1"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2016-4658"
  }, {
    "type" : "WEB",
    "url" : "https://git.gnome.org/browse/libxml2/commit/?id=c1d1f7121194036608bf555f08d3062a36fd344b"
  }, {
    "type" : "WEB",
    "url" : "https://security.gentoo.org/glsa/201701-37"
  }, {
    "type" : "WEB",
    "url" : "https://support.apple.com/HT207141"
  }, {
    "type" : "WEB",
    "url" : "https://support.apple.com/HT207142"
  }, {
    "type" : "WEB",
    "url" : "https://support.apple.com/HT207143"
  }, {
    "type" : "WEB",
    "url" : "https://support.apple.com/HT207170"
  }, {
    "type" : "WEB",
    "url" : "http://lists.apple.com/archives/security-announce/2016/Sep/msg00006.html"
  }, {
    "type" : "WEB",
    "url" : "http://lists.apple.com/archives/security-announce/2016/Sep/msg00008.html"
  }, {
    "type" : "WEB",
    "url" : "http://lists.apple.com/archives/security-announce/2016/Sep/msg00010.html"
  }, {
    "type" : "WEB",
    "url" : "http://lists.apple.com/archives/security-announce/2016/Sep/msg00011.html"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-119" ],
    "severity" : "CRITICAL",
    "github_reviewed" : true,
    "github_reviewed_at" : "2020-06-16T21:35:10Z",
    "nvd_published_at" : "2016-09-25T10:59:02Z"
  }
}