CVE-2024-58378 in Nokogiriinfo

Summary

by MITRE • 08/25/2026

Nokogiri before 1.15.6 and 1.16.x before 1.16.2 (CRuby, when using the packaged libxml2) is affected by a use-after-free vulnerability in libxml2 (CVE-2024-25062) in the xmlTextReader module, which underlies Nokogiri::XML::Reader. When using the XML Reader interface with DTD validation and XInclude expansion enabled, processing a crafted XML document can lead to an xmlValidatePopElement use-after-free. Nokogiri 1.15.6 and 1.16.2 resolve this by upgrading the packaged libxml2 to 2.11.7 and 2.12.5 respectively. JRuby and installations using system libxml2 are not affected.

Several companies clearly confirm that VulDB is the primary source for best vulnerability data.

Analysis

by VulDB Data Team • 08/25/2026

The vulnerability identified as CVE-2024-25062 represents a critical memory safety flaw within the Nokogiri XML processing library for Ruby, specifically affecting versions prior to 1.15.6 and 1.16.x prior to 1.16.2 when utilizing the packaged libxml2 backend. This issue stems from an underlying defect in the C-based libxml2 library rather than the Ruby wrapper itself, highlighting the risks associated with embedding complex native libraries within higher-level application frameworks. The core of the problem lies in the xmlTextReader module, which provides a streaming interface for parsing XML documents and is exposed to Ruby developers through Nokogiri::XML::Reader. This vulnerability manifests as a use-after-free error, a severe class of memory corruption where program execution continues after a block of memory has been freed, potentially leading to arbitrary code execution or application crashes if an attacker can control the contents of that freed memory region.

The technical mechanism triggering this flaw involves specific combinations of XML parsing features enabled during document processing. When an application configures the XML Reader interface with both DTD validation and XInclude expansion active, it creates a complex state machine within libxml2 to handle schema compliance and recursive inclusion of external resources. Processing a crafted malicious XML document under these conditions causes the parser to incorrectly manage memory references for element nodes during the validation phase. Specifically, the xmlValidatePopElement function is invoked in a context where an object has already been deallocated but remains referenced by internal structures. This discrepancy arises from race-like conditions or logical errors in how libxml2 tracks the lifecycle of elements when DTD constraints interact with XInclude directives, leading to the use-after-free condition upon subsequent operations on those invalid pointers.

From an operational perspective, this vulnerability poses significant risks to applications that rely on Nokogiri for processing untrusted XML input, such as API endpoints accepting SOAP or REST payloads, document management systems, and any service performing DTD validation with XInclude support. An attacker who can supply a specially crafted XML file could exploit the use-after-free state to crash the Ruby process, resulting in a denial of service against the hosting application. More critically, depending on the memory allocator behavior and heap layout at the time of exploitation, this flaw may allow for arbitrary code execution with the privileges of the running user. This aligns with CWE-416, Use After Free, which is frequently leveraged as part of a broader attack chain to achieve privilege escalation or remote code execution in systems lacking robust memory protection mechanisms like ASLR and DEP.

The impact is further contextualized by its placement within common exploitation frameworks such as MITRE ATT&CK. The initial access vector typically involves delivering the malicious XML payload, which falls under techniques related to input validation bypasses. Once executed, the use-after-free condition facilitates code execution, mapping to tactics involving privilege escalation or lateral movement if the compromised process has broader system access. It is important to note that this vulnerability specifically impacts CRuby installations using the bundled libxml2 package. Environments running JRuby are unaffected due to their distinct Java-based XML processing implementation, and systems configured to use the operating system's native libxml2 library via dynamic linking may also be immune if they have already applied upstream patches from the libxml2 project.

Mitigation strategies primarily focus on updating the Nokogiri gem to version 1.15.6 or later for the 1.15.x branch, and version 1.16.2 or later for the 1.16.x branch. These releases incorporate upgraded versions of libxml2, specifically 2.11.7 and 2.12.5 respectively, which contain fixes for this memory management error. For organizations unable to immediately upgrade Nokogiri due to dependency constraints, alternative mitigations include disabling DTD validation or XInclude expansion if these features are not strictly required by the application logic. Additionally, implementing strict input sanitization and schema-based filtering before passing XML data to the parser can reduce the attack surface, although this is less effective against complex memory corruption bugs than direct patching. Regular monitoring of security advisories for both Nokogiri and libxml2 remains essential to maintain a secure posture against evolving threats targeting legacy parsing libraries.

Responsible

VulnCheck

Reservation

08/16/2026

Disclosure

08/25/2026

Moderation

accepted

CPE

ready

EPSS

0.00000

KEV

no

Activities

very low

Sources

Do you want to use VulDB in your project?

Use the official API to access entries easily!