GHSA-3w22-6jfg-527w
Nokogiri: Use-After-Free in Nokogiri when replacing an attribute value
Quick fix
GHSA-3w22-6jfg-527w — nokogiri: upgrade to the fixed version with the command below.
bundle update nokogiriDetails
### 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](https://github.com/sparklemotion/nokogiri/security/advisories/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).
Are you affected?
Enter the version of the package you're using.
Affected packages
References
- https://github.com/sparklemotion/nokogiri/security/advisories/GHSA-3w22-6jfg-527w[WEB]
- https://github.com/sparklemotion/nokogiri/pull/3752[WEB]
- https://github.com/sparklemotion/nokogiri/commit/b15b518db9fd15fd6b046f73d1439c282e5cc425[WEB]
- https://github.com/sparklemotion/nokogiri/commit/feaed3c8c9bd9d81d064d4ca09b16044cd705d6f[WEB]
- https://github.com/rubysec/ruby-advisory-db/blob/master/gems/nokogiri/GHSA-3w22-6jfg-527w.yml[WEB]
- https://github.com/sparklemotion/nokogiri[PACKAGE]
- https://github.com/sparklemotion/nokogiri/releases/tag/v1.19.5[WEB]
Check it before you install it
One call answers whether to add this package: known advisories, CISA KEV, and whether the name is a hallucinated or freshly squatted one. No key needed to try it.
curl -s https://vdb.ai.kr/v1/ai/check-packages \
-H 'Content-Type: application/json' \
-d '{"packages":["pkg:gem/nokogiri"]}'