Nokogiri: Use-After-Free in Nokogiri when replacing an attribute value
Published 10 Nov 2026 · Updated 10 Nov 2026
Is your project on an affected nokogiri?
Look after several Rails or Ruby apps? Indie watches up to 15 repos, private ones too, for $5 a month. See Indie
Affected package
- Affected
- <1.19.5
- Fixed in
- 1.19.5
bundle update --conservative nokogiri # Gemfile: '>= 1.19.5'Details
Summary
Nokogiri's CRuby native extension could leave a Ruby wrapper pointing to freed memory when replacing the value of an existing XML attribute via Nokogiri::XML::Node#[]= or Nokogiri::XML::Node#lang=. If Ruby code had already accessed the attribute's child nodes, replacing the value could free those native child nodes while their wrappers remained reachable. Using one of those child nodes afterwards could cause an invalid read and a possible segfault.
This is the same class of issue as GHSA-phwj-rprq-35pp, which was fixed for Attr#value= in Nokogiri 1.19.4.
Nokogiri 1.19.5 preserves all already-wrapped attribute child nodes before replacing the attribute value.
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 directly access an attribute's child nodes and then replace that same attribute's value via Node#[]= or Node#lang=. Nokogiri 1.19.5 makes this pattern safe with no change to the public API.
Mitigation
Upgrade to Nokogiri 1.19.5 or later.
As a workaround, avoid accessing attribute child nodes directly via Attr#children or similar before replacing the same attribute's value.
Credit
This issue was responsibly reported by zx (@manus-pi).
Is GHSA-3w22-6jfg-527w in any of your client repos?
Checking one package by hand is fine. Checking it across forty client projects is not. NPMscan reads the lockfiles in every GitHub repo you pick, finds each project with an affected nokogiri, and gives you the command that fixes it.
More advisories for nokogiri
- LowCVE-2026-126062JRuby: NONET is bypassed for external DTDs and entities when the systemId uses a short-form IPv4 host · 10 Nov 2026
- LowCVE-2026-126063Nokogiri: Mutation XSS through `noscript` content in Nokogiri's HTML5 serializer · 10 Nov 2026
- LowCVE-2026-57435Nokogiri: Possible Use-After-Free when setting an attribute value via `Nokogiri::XML::Attr#value=` or `#content=` · 19 Jun 2026
- LowCVE-2026-57438Nokogiri: Possible Use-After-Free in XInclude Processing · 19 Jun 2026
- LowCVE-2026-57437Nokogiri: Possible Use-After-Free when directly using `NokogirI::XML::XPathContext` beyond document lifetime · 19 Jun 2026
- LowCVE-2026-57436Nokogiri: Possible Use-After-Free when setting `Document#root=` to an invalid node type · 19 Jun 2026
References
- Linkgithub.com/sparklemotion/nokogiri/security/advisories/GHSA-3w22-6jfg-527w
- Linkgithub.com/sparklemotion/nokogiri/pull/3752
- Linkgithub.com/sparklemotion/nokogiri/commit/b15b518db9fd15fd6b046f73d1439c282e5cc425
- Linkgithub.com/sparklemotion/nokogiri/commit/feaed3c8c9bd9d81d064d4ca09b16044cd705d6f
- Linkgithub.com/rubysec/ruby-advisory-db/blob/master/gems/nokogiri/GHSA-3w22-6jfg-527w.yml
- Packagegithub.com/sparklemotion/nokogiri
- Linkgithub.com/sparklemotion/nokogiri/releases/tag/v1.19.5
Advisory data from OSV.dev (opens OSV.dev in a new tab), refreshed daily.