Skip to content
Prototype pollution Write-up Intermediate

Prototype Pollution in fast-xml-parser

The fast-xml-parser package did not properly sanitise XML element names, allowing an attacker to inject a __proto__ key that polluted the JavaScript Object prototype. An attacker could then set arbitrary properties on all objects, potentially leading to unexpected behaviour or remote code execution if a gadget exists.

Sudhanshu Rajbhar Follow

Published on github.com

History

Sudhanshu Rajbhar (@sudhanshur705), on github.com

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

The XML parser did not filter or escape the special key __proto__ when converting XML elements to JavaScript object properties.

Impact

This could lead to unexpected results and, by chaining with a prototype pollution gadget, might even lead to remote code execution in some cases.

What the attacker needed

Application parses attacker-controlled XML; a prototype pollution gadget exists for RCE

How it was found

  1. Create an XML string with an element named __proto__ containing a child element.
  2. Parse the XML string using the XMLParser from fast-xml-parser.
  3. 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 JavaScript bug where an attacker can add or change properties on the base object that all other objects inherit from. Here, parsing XML with a special element name let the attacker set a property on that base object, so every object in the program suddenly had that property. This can break the application or, in rare cases, be used to run attacker code.

What is Prototype pollution?

Input changes JavaScript's shared object prototype, altering behaviour across the application, sometimes to XSS or code execution.

More by Sudhanshu Rajbhar

View all

12 more disclosed reports, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Prototype pollution

The lesson behind this report.

Input changes JavaScript's shared object prototype, altering behaviour across the application, sometimes to XSS or code execution.