CVE-2026-57236: Nokogiri: Possible Use-After-Free when `Nokogiri::XML::Document#encoding=` raises an exception
Nokogiri is an open source XML and HTML library for the Ruby programming language. Prior to 1.19.4, calling Document#encoding= with an invalid encoding (e.g., a non-string, or a string containing a null byte) raises an exception, but only after freeing the document's current encoding string without replacing it. The document is left referencing freed memory, so the next call to Document#encoding reads invalid memory, which can cause a segfault or leak freed bytes into a Ruby String. Affects the CRuby (libxml2) implementation only; JRuby is not affected. This vulnerability is fixed in 1.19.4.
Other sources
Nokogiri: Possible Use-After-Free when Nokogiri::XML::Document#encoding= raises an exception
— Microsoft
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade to a fixed release to a version that resolves this vulnerability.
Fixed in 1.19.4-1 - Upgrade
Upgrade
Nokogirito a version that resolves this vulnerability.Fixed in 1.19.4
Event History
Frequently Asked Questions
What is the severity of CVE-2026-57236?
The severity of CVE-2026-57236 is rated as risk 37.
How do I fix CVE-2026-57236?
To fix CVE-2026-57236, update Nokogiri to version 1.19.4 or later.
What kind of vulnerability is CVE-2026-57236?
CVE-2026-57236 is categorized as a Use After Free vulnerability.
When was CVE-2026-57236 published?
CVE-2026-57236 was published on June 25, 2026.
What is affected by CVE-2026-57236?
CVE-2026-57236 affects the Nokogiri library for Ruby when handling invalid encodings.