Round-trip instability in REXML
REXML's XML parser and serialiser can change the structure of a document when it is parsed and then serialised again, so that a round-trip through REXML alters the document's meaning. An attacker could use this to tamper with XML-based protocols such as SAML, potentially bypassing authentication or access controls.
- Triaged in under an hour
- Fixed in 49 days
- Paid in 50 days
- Disclosed after 58 days
Submitted previously via email to [email protected] due to REXML not being listed under in-scope assets here. Explicitly requested by @hsbt to re-submit through HackerOne.
CVSS rating calculated based on confirmed downstream impact.
Hi Ruby Security Team,
I'm reaching out to you to report a vulnerability in REXML that renders downstream use-cases susceptible to varying degrees of tampering.
Conceptually the vulnerability is similar to Go encoding/xml bugs publicly disclosed in December. For context, high-level descriptions of those vulnerabilities can be found in the blog post at https://mattermost.com/blog/coordinated-disclosure-go-xml-vulnerabilities/ and in the advisories it references.
In the case of REXML, the specific vulnerability is best explained using a code example:
require 'rexml/document'
doc = REXML::Document.new <<XML
<!DOCTYPE x [ <!NOTATION x SYSTEM 'x">]><!--'> ]>
<X>
<Y/><![CDATA[--><X><Z/><!--]]>-->
</X>
XML
puts "First child in original doc: " + doc.root.elements[1].name
doc = REXML::Document.new doc.to_s
puts "First child after round-trip: " + doc.root.elements[1].name
This program prints two lines of text:
First child in original doc: Y
First child after round-trip: Z
The output demonstrates how the structure of an XML document can change when parsed and serialized using REXML. The expected output from a well-behaving parser would be such where both lines end with "Y".
Regards,
Juho Nurminen Staff Product Security Engineer, Mattermost, Inc.
Impact
The impact of XML round-trip issues can vary significantly depending on context. SAML implementations affected by such issues can allow authentication bypasses and privilege escalation. SOAP endpoints can allow circumventing business logic or access controls. And in general XML processing loses integrity guarantees.
We are aware of a major SAML implementation affected by this vulnerability, resulting in critical impact in all applications that rely on it. The vulnerability has not been reported to the downstream maintainers since it is an issue in REXML.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Impact
Downstream XML consumers such as SAML implementations could allow authentication bypasses and privilege escalation, and SOAP endpoints could have business logic or access controls circumvented, though the report notes that impact varies by context.
What the attacker needed
Application uses REXML to parse and re-serialise XML; attacker can supply the XML input
How it was found
- Create an XML document containing a DOCTYPE with a NOTATION declaration, a comment, and a CDATA section that together cause ambiguity.
- Parse the document with REXML and note the name of the first child element.
- Serialise the parsed document back to a string with REXML.
- Parse the serialised string again with REXML and note the name of the first child element.
- Observe that the first child's name changed from Y to Z after the round-trip.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
XML is a text format for structured data, and a parser turns that text into a tree of elements. REXML is a Ruby library that both reads and writes XML. This report shows that if you read a document with REXML and then write it back out, the result can be a different document, which matters when security decisions are based on the parsed form.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.