Read the docs
TI-2026-66872 Aliases GHSA-5v8h-3h3q-446p

Nokogiri: Possible Use-After-Free when `Nokogiri::XML::Document#encoding=` raises an exception

Priority LOW 38CWE-416Published · Updated

Key facts

Attack vector
—
Privileges required
—
User interaction
—
Attack complexity
—
Impact type
—
Confidentiality · integrity · availability
—
Fix status
Fixed

No CVSS vector from any source. Fix status from GitHub.

Summary

### Summary 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. ### Severity The Nokogiri maintainers have evaluated this as low severity. Reaching it requires an unusual API-usage pattern that does not arise during normal use. The application must pass an invalid encoding to `Document#encoding=`, rescue the resulting exception, and then continue using the same document. Nokogiri 1.19.4 makes this pattern safe with no change to the public API. The document no longer references freed memory after the exception is raised. ### Mitigation Upgrade to Nokogiri 1.19.4 or later. If users are unable to upgrade, avoid passing attacker-controlled values to `Document#encoding=`. Applications that only assign developer-authored encodings are not directly exposed. ### Credit This issue was responsibly reported by Zheng Yu from depthfirst.com.

Why it matters now

Fix Fixed nokogiri (RubyGems): 1.19.4

SSVC decision points

Not available: CISA has not published SSVC decision points for this record.

Affected products

VendorProductAffected versionsFixed inStatusSource
—nokogiri (RubyGems)before 1.19.41.19.4Patch availableGHSA-5v8h-3h3q-446p
  • nokogiri (RubyGems) Vendor— Affected before 1.19.4 Fixed in 1.19.4 Patch available GHSA-5v8h-3h3q-446p

Remediation

  • Fix · GHSA-5v8h-3h3q-446p nokogiri (RubyGems) Fixed in 1.19.4 Advisory →

Timeline

  1. 2026-10-03 Threatist record created from GHSA-5v8h-3h3q-446p

References

Sources

This product uses the NVD API but is not endorsed or certified by the NVD. Sources and licences