CVE-2022-29181: Nokogiri Nokogiri Improperly Handles Unexpected Data Vulnerability

HIGH
Advisory Identifier: GHSA-xh29-r2w5-wx8m
CVSS 8.2
CWE-843 CWE-241
Published
Advisory Summary

CVE-2022-29181 is a HIGH (CVSS 8.2) nokogiri improperly handles unexpected data vulnerability (CWE-843: Access of Resource Using Incompatible Type ('Type Confusion')) affecting Nokogiri libraries in the RubyGems ecosystem. The issue involves nokogiri improperly handles unexpected data type. Remediation is available by upgrading affected packages to version 1.13.6.

CVE-2022-29181 at a Glance

CVE Identifier CVE-2022-29181
GHSA Identifier GHSA-xh29-r2w5-wx8m
Severity HIGH
CVSS v3.1 Base Score 8.2
CWE Classification CWE-843: Access of Resource Using Incompatible Type ('Type Confusion')
Affected Product Nokogiri
Package Ecosystem RubyGems
Published Date
Last Updated

Security Impact

CVSS: 8.2

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:N/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 None (I:N)
Availability High (A:H)

How to Fix CVE-2022-29181

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.13.6
Upgrade nokogiri to 1.13.6
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-2022-29181, 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.13.6), 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-843: Access of Resource Using Incompatible Type ('Type Confusion'), where the product allocates or initializes a resource such as a pointer, object, or variable using one type, but it later accesses that resource using a type that is incompatible with the original type. 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

### Summary Nokogiri `< v1.13.6` does not type-check all inputs into the XML and HTML4 SAX parsers. For CRuby users, this may allow specially crafted untrusted inputs to cause illegal memory access errors (segfault) or reads from unrelated memory. ### Severity The Nokogiri maintainers have evaluated this as **High 8.2** (CVSS3.1). ### Mitigation CRuby users should upgrade to Nokogiri `>= 1.13.6`. JRuby users are not affected. ### Workarounds To avoid this vulnerability in affected applications, ensure the untrusted input is a `String` by calling `#to_s` or equivalent. ### Credit This vulnerability was responsibly reported by @agustingianni and the Github Security Lab.

CVE-2022-29181 Affected Nokogiri Versions

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

References

Frequently Asked Questions

What is CVE-2022-29181?
CVE-2022-29181 is a security vulnerability in Nokogiri involving Nokogiri Improperly Handles Unexpected Data Type under CWE-843: Access of Resource Using Incompatible Type ('Type Confusion').
Which Nokogiri versions are affected?
Affected versions include releases prior to 1.13.6 across affected packages: nokogiri.
What version fixes CVE-2022-29181?
Upgrading to 1.13.6 (or the latest patched release for your respective branch) resolves the vulnerability.
Is nokogiri affected?
Yes, nokogiri is affected in releases prior to 1.13.6. Upgrade your dependency to 1.13.6 or later.
What is the CVSS score of CVE-2022-29181?
CVE-2022-29181 has a CVSS v3.1 base score of 8.2 (HIGH) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:N/A:H.
What CWE is associated with CVE-2022-29181?
CVE-2022-29181 is classified under CWE-843: Access of Resource Using Incompatible Type ('Type Confusion') (The product allocates or initializes a resource such as a pointer, object, or variable using one type, but it later accesses that resource using a type that is incompatible with the original type.).
How can I check RubyGems dependencies for CVE-2022-29181?
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-xh29-r2w5-wx8m",
  "modified" : "2025-05-27T14:51:05Z",
  "published" : "2022-05-23T23:15:15Z",
  "aliases" : [ "CVE-2022-29181" ],
  "summary" : "Nokogiri Improperly Handles Unexpected Data Type",
  "details" : "### Summary\n\nNokogiri `< v1.13.6` does not type-check all inputs into the XML and HTML4 SAX parsers. For CRuby users, this may allow specially crafted untrusted inputs to cause illegal memory access errors (segfault) or reads from unrelated memory.\n\n### Severity\n\nThe Nokogiri maintainers have evaluated this as **High 8.2** (CVSS3.1).\n\n\n### Mitigation\n\nCRuby users should upgrade to Nokogiri `>= 1.13.6`.\n\nJRuby users are not affected.\n\n\n### Workarounds\n\nTo avoid this vulnerability in affected applications, ensure the untrusted input is a `String` by calling `#to_s` or equivalent.\n\n\n### Credit\n\nThis vulnerability was responsibly reported by @agustingianni and the Github Security Lab.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:N/A:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "RubyGems",
      "name" : "nokogiri"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "1.13.6"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/sparklemotion/nokogiri/security/advisories/GHSA-xh29-r2w5-wx8m"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2022-29181"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/sparklemotion/nokogiri/commit/83cc451c3f29df397caa890afc3b714eae6ab8f7"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/sparklemotion/nokogiri/commit/db05ba9a1bd4b90aa6c76742cf6102a7c7297267"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/rubysec/ruby-advisory-db/blob/master/gems/nokogiri/CVE-2022-29181.yml"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/sparklemotion/nokogiri"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/sparklemotion/nokogiri/releases/tag/v1.13.6"
  }, {
    "type" : "WEB",
    "url" : "https://security.gentoo.org/glsa/202208-29"
  }, {
    "type" : "ADVISORY",
    "url" : "https://securitylab.github.com/advisories/GHSL-2022-031_GHSL-2022-032_Nokogiri"
  }, {
    "type" : "WEB",
    "url" : "https://support.apple.com/kb/HT213532"
  }, {
    "type" : "WEB",
    "url" : "http://seclists.org/fulldisclosure/2022/Dec/23"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-241", "CWE-843" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2022-05-23T23:15:15Z",
    "nvd_published_at" : "2022-05-20T19:15:00Z"
  }
}