CVE-2026-57236: Nokogiri use-after-free in Document encoding assignment

CVE-2026-57236 · Severity: medium · CVSS 4 · Published 2026-06-25

Nokogiri is a widely used Ruby library for processing XML and HTML documents. A technical flaw in how the library handles document encoding can lead to application crashes or the accidental leakage of small amounts of internal memory. This issue only occurs if an application attempts to set an invalid encoding, fails, and then continues to use the same document object.

Technologies: nokogiri (RubyGems). Vendors: RubyGems.

Quick answers

Is CVE-2026-57236 exploited in the wild?
No. Junglewise Threat Intelligence has no report of CVE-2026-57236 being exploited in the wild.
How severe is CVE-2026-57236?
Medium severity, with a CVSS score of 4, published 25 June 2026.
Which products and versions are affected?
nokogiri (RubyGems) ECOSYSTEM:introduced=0,fixed=1.19.4.
Is there a fix for CVE-2026-57236?
Yes. nokogiri (RubyGems): upgrade to 1.19.4 or later. Junglewise finds every place you run it, drafts the upgrade and applies it once you approve.
How is CVE-2026-57236 attacked?
It is attacked over the network, in a software library.
Am I affected by CVE-2026-57236?
Check whether you run nokogiri (RubyGems) at an affected version. Junglewise does that check for you around the clock: connect your code, cloud and domains, and it matches new vulnerabilities like this one against what you actually run and tells you when one reaches you.

How to fix

  • nokogiri (RubyGems): upgrade to 1.19.4 or later
    bundle update nokogiri

Technical details

A Use-After-Free (CWE-416) vulnerability exists in the CRuby (libxml2) implementation of Nokogiri. When `Document#encoding=` is called with an invalid argument (such as a non-string or a string containing a null byte), the library frees the existing encoding string before validating the new input. If validation fails and an exception is raised, the document's internal pointer still references the freed memory. Subsequent calls to `Document#encoding` will perform a read on this invalid memory, which can result in a segmentation fault or the leakage of freed bytes into a Ruby String. This issue is fixed in version 1.19.4.

Affected products

  • sparklemotion Nokogiri < 1.19.4

Identifiers

  • CVE-2026-57236
  • GHSA-5v8h-3h3q-446p

Timeline

  • 2026-06-18: advisory: GitHub Security Advisory published by maintainers
  • 2026-06-25: disclosed: CVE published to NVD

References

This page as Markdown. Free to reuse under CC BY 4.0 with a link back.