CVE-2026-57436: Nokogiri XML/HTML Library Use-After-Free Vulnerability
Nokogiri, a popular Ruby library for parsing and manipulating XML and HTML documents, contains a memory safety bug in versions prior to 1.19.4. The vulnerability allows an attacker to set an invalid type of object (specifically a DTD node) as a document's root element, bypassing validation checks. This causes the library to crash or behave unpredictably when the invalid structure is processed during garbage collection. The issue is resolved in version 1.19.4 and later.
Source data · NVD / CISA · public domain
- CVSS
- 3.1 · 5.3 MEDIUM · CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:L
- Weaknesses (CWE)
- CWE-416
- Affected products
- 1 configuration(s)
- Published / Modified
- 2026-06-25 / 2026-06-26
NVD description (verbatim)
Nokogiri is an open source XML and HTML library for the Ruby programming language. Prior to 1.19.4, Nokogiri::XML::Document#root= validated only that the new root was a Nokogiri::XML::Node, allowing a DTD node to be set as the document root. The result is a heap use-after-free during garbage collection or finalization, leading to an invalid memory read or potentially a segfault. This vulnerability is fixed in 1.19.4.
1 reference(s) · View on NVD →
SEC.co analysis · AI-assisted, reviewed against source
Technical summary
CVE-2026-57436 is a use-after-free vulnerability in Nokogiri's Nokogiri::XML::Document#root= method. Prior to version 1.19.4, the method validated incoming arguments only by checking if they were instances of Nokogiri::XML::Node, without verifying whether the node type was appropriate for document root assignment. A DTD node, while technically a Node subclass, is not a valid document root. When such a node is improperly set as the root, subsequent garbage collection or object finalization triggers a heap use-after-free condition (CWE-416), leading to invalid memory access and potential segmentation faults. The fix implements stricter type validation to reject invalid node types before assignment.
Business impact
Ruby applications relying on Nokogiri for XML/HTML processing face availability risk if attackers can supply malformed documents. A successful exploit causes application crashes, resulting in service disruptions. Web services, document processors, and data parsing pipelines built on Nokogiri are most affected. The moderate CVSS score reflects the availability impact; there is no confidentiality or integrity compromise. Organizations should prioritize upgrading to mitigate denial-of-service scenarios, particularly if user-supplied content is processed.
Affected systems
Nokogiri versions before 1.19.4 are vulnerable. The library is widely used across Ruby on Rails applications, content management systems, API services, and data processing scripts. Any Ruby application using Nokogiri for XML/HTML parsing without pinning to version 1.19.4 or later is at risk.
Exploitability
Exploitation requires the ability to supply or influence XML/HTML documents processed by a vulnerable Nokogiri instance. Network vector indicates remote exploitation is possible if the application accepts untrusted input over the network (e.g., API endpoints, file upload features, or web scrapers). No authentication or user interaction is required. However, the attack results in denial of service rather than code execution or data breach, limiting the scope of impact. The vulnerability is not listed in CISA's Known Exploited Vulnerabilities catalog.
Remediation
Upgrade Nokogiri to version 1.19.4 or later. This is a straightforward remediation requiring a dependency update and testing in your application environment. Ruby developers should update their Gemfile and run bundle update nokogiri, then redeploy affected services. No configuration changes or workarounds are necessary.
Patch guidance
Update Nokogiri to version 1.19.4 or any later version. For Ruby projects, modify your Gemfile to specify gem 'nokogiri', '~> 1.19.4' or higher, then execute bundle update nokogiri. Test the upgrade in a staging environment to ensure compatibility with your application, particularly if you have custom XML/HTML parsing logic or rely on specific Nokogiri APIs. Verify that document root operations continue to function as expected after the update.
Detection guidance
Monitor your Ruby dependency inventory for Nokogiri versions below 1.19.4 using software composition analysis (SCA) tools such as Bundler-audit, Dependabot, or Snyk. In production environments, observe application error logs for segmentation faults or heap corruption messages originating from Nokogiri operations, particularly when processing untrusted XML/HTML documents. Intrusion detection systems are unlikely to identify this vulnerability reliably since it manifests as memory corruption rather than network-level attack patterns; focus on preventive patching rather than runtime detection.
Why prioritize this
Although the CVSS score is moderate (5.3), this vulnerability warrants prompt attention because (1) Nokogiri is a foundational dependency in many Ruby applications, (2) exploitation is effortless given network vector and no authentication requirement, and (3) the fix is simple and low-risk. The lack of KEV status does not diminish urgency—patching should be completed within your standard maintenance cycle, ideally within 2–4 weeks for non-critical systems and 1–2 weeks for internet-facing services processing untrusted input.
Risk score, explained
CVSS 5.3 (Medium) reflects a network-accessible vulnerability with low complexity and no privilege/interaction barriers, but limited impact scope (availability only, no C/I). The vector CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:L confirms remote exploitability and denial-of-service outcome. The score appropriately balances the ease of triggering the bug against the limited severity of the resulting crash. In context, organizations processing untrusted documents should treat this as higher priority despite the moderate base score.
Frequently asked questions
Can an attacker execute code or steal data via this vulnerability?
No. CVE-2026-57436 results in a memory access violation and application crash (denial of service). It does not enable code execution, data theft, or privilege escalation. The impact is limited to availability.
Do I need to do anything if my Ruby application does not directly parse untrusted XML or HTML?
You should still upgrade Nokogiri to 1.19.4+ as a precaution. If any dependency in your bundle processes untrusted content and relies on Nokogiri indirectly, you remain exposed. Additionally, the patch carries minimal risk, making proactive upgrades sensible.
What versions of Ruby does this patch support?
Nokogiri 1.19.4 supports Ruby 2.6+. Consult the official Nokogiri release notes and your Ruby version compatibility matrix before upgrading to ensure your environment meets the requirements.
Is there a workaround if I cannot upgrade immediately?
No reliable workaround exists. The vulnerability is in the validation logic itself. If you must delay patching, implement input validation at the application layer to reject or sanitize malformed XML/HTML before passing it to Nokogiri. However, this is error-prone and not a substitute for upgrading.
This analysis is based on published vulnerability data as of 2026-06-25. Organizations should verify patch availability and compatibility with their specific environments before deployment. The information provided is for educational and risk management purposes and does not constitute professional security advice. Always consult official vendor advisories and your security team before implementing changes in production. Source: NVD (public-domain), retrieved 2026-08-03. Analysis generated by SEC.co (claude-haiku-4-5).
Related vulnerabilities
- CVE-2026-57437MEDIUMNokogiri XPathContext Use-After-Free Memory Safety Vulnerability
- CVE-2026-57438MEDIUMNokogiri XInclude Use-After-Free Vulnerability (CVSS 6.6)
- CVE-2026-57236HIGHNokogiri Use-After-Free in Document Encoding (CVSS 8.2)
- CVE-2026-57435HIGHNokogiri XML Attribute Memory Corruption (DoS)
- CVE-2025-55644MEDIUMHeap Use-After-Free in GPAC MP4Box v2.4 DoS Vulnerability
- CVE-2025-55650MEDIUMHeap Use-After-Free in GPAC MP4Box v2.4 DoS Vulnerability
- CVE-2025-60466MEDIUMGPAC MP4Box Use-After-Free DoS Vulnerability
- CVE-2025-60471MEDIUMUse-After-Free in GPAC MP4Box Before 26.02.0 Denial of Service