CVE-2022-50998 Overview
CVE-2022-50998 affects Nokogiri versions prior to 1.13.9 when using the CRuby implementation with packaged libraries. The affected releases bundle libxml2 v2.9.14, which is vulnerable to CVE-2022-40304 (data corruption and double-free triggered by an entity reference cycle when entity content is allocated from a dict) and CVE-2022-40303 (integer overflows when parsing with XML_PARSE_HUGE). Processing crafted XML input can lead to denial of service or memory corruption in applications that rely on Nokogiri for XML parsing. Nokogiri 1.13.9 resolves the issue by upgrading the packaged libxml2 to v2.10.3.
Critical Impact
Crafted XML input processed by vulnerable Nokogiri versions can trigger memory corruption or denial of service in Ruby applications.
Affected Products
- Nokogiri versions prior to 1.13.9 (CRuby implementation using packaged libraries)
- Bundled libxml2 v2.9.14
- Ruby applications and services that pass untrusted XML through Nokogiri
Discovery Timeline
- 2026-08-25 - CVE-2022-50998 published to NVD
- 2026-08-27 - Last updated in NVD database
Technical Details for CVE-2022-50998
Vulnerability Analysis
Nokogiri versions before 1.13.9 ship a vulnerable copy of libxml2 (v2.9.14). Two distinct memory safety issues in libxml2 propagate into every application using the packaged build. CVE-2022-40304 causes data corruption and a potential double-free through an entity reference cycle when entity content is allocated from a dictionary. CVE-2022-40303 introduces integer overflows on the parsing paths gated by the XML_PARSE_HUGE option.
Both issues can be reached by parsing attacker-controlled XML. Successful exploitation can crash the process or corrupt heap state, affecting availability and potentially memory integrity. The advisory also references CVE-2022-2309, a NULL pointer dereference [CWE-476] via iterwalk/canonicalize, but maintainers determined it does not affect Nokogiri users.
Root Cause
The root cause resides in libxml2, not in Nokogiri's Ruby code. libxml2 v2.9.14 fails to validate entity reference cycles safely when entity content is dict-allocated, leading to a double-free. Separately, arithmetic on parser buffer sizes overflows when XML_PARSE_HUGE relaxes normal input limits. Nokogiri inherits these flaws by statically bundling the vulnerable libxml2 release.
Attack Vector
An attacker delivers a crafted XML document to an endpoint or component that parses input with Nokogiri. The malicious document either contains a circular entity reference or exercises the huge-parse path with values chosen to overflow internal size calculations. No authentication or user interaction is required when the parser is exposed over the network. See the GitHub Security Advisory GHSA-2qc6-mcvw-92cw for the technical write-up.
No public proof-of-concept code has been verified for this Nokogiri advisory. Refer to the VulnCheck Advisory on Nokogiri for additional context on the bundled libxml2 issues.
Detection Methods for CVE-2022-50998
Indicators of Compromise
- Unexpected crashes or segmentation faults in Ruby processes that parse XML with Nokogiri.
- Application logs showing libxml2 parser errors on documents containing recursive entity references.
- Anomalous spikes in memory usage or CPU time correlated with XML parsing requests.
Detection Strategies
- Inventory Ruby applications and Gemfile.lock files for Nokogiri versions below 1.13.9.
- Use software composition analysis (SCA) to flag bundled libxml2 v2.9.14 in build artifacts and container images.
- Inspect XML ingress points for documents with entity DTDs or oversized structures consistent with XML_PARSE_HUGE abuse.
Monitoring Recommendations
- Alert on repeated Ruby worker restarts or crash-loop patterns tied to XML processing endpoints.
- Capture and review WAF or API gateway logs for XML payloads with excessive entity nesting.
- Track dependency updates in CI/CD to ensure downstream services rebuild against a patched Nokogiri.
How to Mitigate CVE-2022-50998
Immediate Actions Required
- Upgrade Nokogiri to 1.13.9 or later across all Ruby services and worker images.
- Rebuild and redeploy container images so bundled native extensions link against the patched libxml2 v2.10.3.
- Audit third-party gems that transitively depend on Nokogiri and update their pins accordingly.
Patch Information
Nokogiri 1.13.9 upgrades the packaged libxml2 to v2.10.3, which resolves both CVE-2022-40304 and CVE-2022-40303. The upstream fixes are captured in the Nokogiri repository, including commit 644a89e0 and commit c8469863. Review the GitHub Security Advisory GHSA-2qc6-mcvw-92cw before deploying.
Workarounds
- Where upgrading is not immediately possible, disable XML_PARSE_HUGE and reject documents that declare custom entity DTDs.
- Constrain XML input size at the network edge and validate schemas before invoking Nokogiri.
- Isolate XML parsing workloads so a crash cannot affect unrelated services.
# Upgrade Nokogiri to the patched release
bundle update nokogiri --conservative
# Verify the installed version links against libxml2 2.10.3 or later
ruby -rnokogiri -e 'puts Nokogiri::VERSION_INFO.inspect'
Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

