Prototype Pollution in xml2js
The xml2js library is vulnerable to prototype pollution when parsing XML that contains a __proto__ element, allowing an attacker to add arbitrary properties to the prototype of the resulting object. This could lead to unexpected behaviour or further exploitation in applications that use the parsed object.
Published on github.com
History
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the XML parser does not properly sanitise element names such as __proto__ when converting XML to a JavaScript object, allowing prototype pollution.
Impact
An attacker could pollute the prototype of the parsed object, potentially leading to unexpected behaviour or further exploitation in the application.
What the attacker needed
Application parses untrusted XML with xml2js
How it was found
- Use the xml2js parseString function to parse an XML string that contains a __proto__ element with a child element.
- Observe that the resulting object's prototype has been polluted with the child element's name and value.
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 write-up has not been written yet. The Original tab links to the source.
Prototype pollution is a bug where an attacker can add or change properties on a base object that many other objects inherit from. In this case, parsing a specially crafted XML document causes the parser to modify the prototype of the result object, which can affect how the application behaves.
What is Prototype pollution?
Input changes JavaScript's shared object prototype, altering behaviour across the application, sometimes to XSS or code execution.