GHSA-phwj-rprq-35pp: Nokogiri Possible Use-After-Free When Setting An Vulnerability

LOW
CWE-825 CWE-416
Published
Advisory Summary

GHSA-phwj-rprq-35pp is a LOW possible use-after-free when setting an vulnerability (CWE-825: Expired Pointer Dereference) affecting Nokogiri libraries in the RubyGems ecosystem. The issue involves possible use-after-free when setting an attribute value via `nokogiri::xml::attr#value=` or `#content=`. Remediation is available by upgrading affected packages to version 1.19.4.

GHSA-phwj-rprq-35pp at a Glance

CVE Identifier N/A
GHSA Identifier GHSA-phwj-rprq-35pp
Severity LOW
CVSS v3.1 Base Score N/A
CWE Classification CWE-825: Expired Pointer Dereference
Affected Product Nokogiri
Package Ecosystem RubyGems
Published Date
Last Updated

How to Fix GHSA-phwj-rprq-35pp

To remediate this vulnerability, upgrade all affected Nokogiri dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

nokogiri fixed: 1.19.4
Upgrade nokogiri to 1.19.4
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

inspect dependencies for nokogiri

How to Check if You Are Affected

To determine whether your application is affected by GHSA-phwj-rprq-35pp, inspect your project dependencies for Nokogiri:

inspect dependencies for nokogiri

Analyze the terminal output to locate any version of Nokogiri in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 1.19.4), your application is affected.

Note: Verify declared build manifests and deployed runtime container environments.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-825: Expired Pointer Dereference, where the product dereferences a pointer that contains a location for memory that was previously valid, but is no longer valid. In Nokogiri, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### Summary Nokogiri’s CRuby native extension could leave a Ruby wrapper pointing to freed memory when replacing the value of an XML attribute. If Ruby code had already accessed an attribute child node, `Nokogiri::XML::Attr#value=` could free the underlying native child node while the wrapper remained reachable through the document node cache. A later use of the freed child node or a Ruby GC mark could dereference an invalid pointer, causing an invalid read and a possible segfault. Nokogiri 1.19.4 preserves any 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 node and then replace that same attribute's value via `Attr#value=` or `#content=`. Nokogiri 1.19.4 makes this pattern safe with no change to the public API. Already-wrapped attribute child nodes are preserved before the value is replaced. ### Mitigation Upgrade to Nokogiri 1.19.4 or later. As a workaround, avoid accessing attribute child nodes directly via `Attr#child` or similar before mutating the same attribute’s value. ### Credit This issue was responsibly reported by Zheng Yu from depthfirst.com.

GHSA-phwj-rprq-35pp Affected Nokogiri Versions

1 component(s)
Fixed Versions:
1.19.4
Product / Package Ecosystem Affected Versions Fixed Version
nokogiri
RubyGems
< 1.19.4
1.19.4

References

Frequently Asked Questions

What is GHSA-phwj-rprq-35pp?
GHSA-phwj-rprq-35pp is a security vulnerability in Nokogiri involving Possible Use-After-Free when setting an attribute value via `Nokogiri::XML::Attr#value=` or `#content=` under CWE-825: Expired Pointer Dereference.
Which Nokogiri versions are affected?
Affected versions include releases prior to 1.19.4 across affected packages: nokogiri.
What version fixes GHSA-phwj-rprq-35pp?
Upgrading to 1.19.4 (or the latest patched release for your respective branch) resolves the vulnerability.
Is nokogiri affected?
Yes, nokogiri is affected in releases prior to 1.19.4. Upgrade your dependency to 1.19.4 or later.
What CWE is associated with GHSA-phwj-rprq-35pp?
GHSA-phwj-rprq-35pp is classified under CWE-825: Expired Pointer Dereference (The product dereferences a pointer that contains a location for memory that was previously valid, but is no longer valid.).
How can I check RubyGems dependencies for GHSA-phwj-rprq-35pp?
Run the dependency tree command: 'inspect dependencies for nokogiri'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-phwj-rprq-35pp",
  "modified" : "2026-06-19T16:37:46Z",
  "published" : "2026-06-19T16:37:46Z",
  "aliases" : [ ],
  "summary" : "Nokogiri: Possible Use-After-Free when setting an attribute value via `Nokogiri::XML::Attr#value=` or `#content=`",
  "details" : "### Summary\n\nNokogiri’s CRuby native extension could leave a Ruby wrapper pointing to freed memory when replacing the value of an XML attribute. If Ruby code had already accessed an attribute child node, `Nokogiri::XML::Attr#value=` could free the underlying native child node while the wrapper remained reachable through the document node cache. A later use of the freed child node or a Ruby GC mark could dereference an invalid pointer, causing an invalid read and a possible segfault.\n\nNokogiri 1.19.4 preserves any already-wrapped attribute child nodes before replacing the attribute value.\n\nJRuby is not affected.\n\n### Severity\n\nThe 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 node and then replace that same attribute's value via `Attr#value=` or `#content=`. Nokogiri 1.19.4 makes this pattern safe with no change to the public API. Already-wrapped attribute child nodes are preserved before the value is replaced.\n\n### Mitigation\n\nUpgrade to Nokogiri 1.19.4 or later.\n\nAs a workaround, avoid accessing attribute child nodes directly via `Attr#child` or similar before mutating the same attribute’s value.\n\n### Credit\n\nThis issue was responsibly reported by Zheng Yu from depthfirst.com.",
  "severity" : [ {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:N/VI:N/VA:L/SC:N/SI:N/SA:N/E:U"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "RubyGems",
      "name" : "nokogiri"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "1.19.4"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/sparklemotion/nokogiri/security/advisories/GHSA-phwj-rprq-35pp"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/sparklemotion/nokogiri"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-416", "CWE-825" ],
    "severity" : "LOW",
    "github_reviewed" : true,
    "github_reviewed_at" : "2026-06-19T16:37:46Z",
    "nvd_published_at" : null
  }
}