CVE-2022-29181: Nokogiri Nokogiri Improperly Handles Unexpected Data Vulnerability
HIGHCVE-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
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).
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.
Upgrade nokogiri to 1.13.6
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
CVE-2022-29181 Affected Nokogiri Versions
1 component(s)| Product / Package | Ecosystem | Affected Versions | Fixed Version |
|---|---|---|---|
|
nokogiri
|
RubyGems |
< 1.13.6
|
1.13.6
|
References
Frequently Asked Questions
What is CVE-2022-29181?
Which Nokogiri versions are affected?
What version fixes CVE-2022-29181?
Is nokogiri affected?
What is the CVSS score of CVE-2022-29181?
What CWE is associated with CVE-2022-29181?
How can I check RubyGems dependencies for CVE-2022-29181?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"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"
}
}