A successful prototype pollution chained to a DOM XSS
The application allowed prototype pollution via the URL fragment, which was not filtered, and a polluted property was later used as an attribute in a style tag, enabling DOM XSS. An attacker could inject an event handler to execute JavaScript.
Published on medium.com
I recently found a vulnerability that is a little less common and quite interesting in how it works.
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.
Context
This write-up describes a prototype pollution bug that the author chained into a DOM XSS. The target is a private program, so the author deliberately changed some details and refers to the site as www.example.com. The report does not name the product or the feature beyond that: it says only that while researching the site the author found several other issues (XSS, iframe injection), which suggested that user input was not always filtered correctly.
The relevant behaviour is that the application reads the URL, including the fragment, and uses the values it finds there. That is what made the fragment a usable entry point for the pollution.
Setup
No accounts, roles, tools or versions are described. The work was done against a live site behind a WAF, using the browser console to check whether the prototype had been polluted, and the source code of the application's JavaScript to find the function that processed the input. The author also used web archive to look at historical URLs for the target.
Finding it
The starting point was the observation that user input on the site was not always filtered, based on other injection issues found earlier. The author then asked whether prototype pollution could be delivered through the URL, reasoning that a lax filtering policy would make something interesting possible.
Step 1: a basic attempt, blocked by the WAF
The first payload was the obvious one, using the __proto__ key directly in the query string:
?__proto__.zhero=zhero
The WAF blocked it. Several further attempts, including ones going through the constructor, were also blocked systematically by the firewall.
Step 2: bypass attempts
Two bypass ideas were tried. The first assumes the input is not recursively sanitised, so a nested __proto__ survives a single-pass filter:
?__pro__proto__to__.zhero=zhero
The second goes through the constructor, which is itself an object and therefore also inherits a prototype:
constructor[prototype][zhero]=zhero
The author notes that for each case both ways of accessing an object, dot notation and bracket notation, should be tested, because the difference can matter after a WAF bypass depending on how the URL and its parameters are processed. These attempts did not get through.
Step 3: moving to the fragment
Looking through web archive for the target, the author noticed that many URLs contained the # character followed by useful information. That indicated it was not just an anchor, and that if the application used this character, the function handling the URL and its parameters must take it into account. The payload was moved into the fragment:
#__proto__[zhero]=zhero
This request passed with no problem from the WAF. A small test in the console confirmed that the prototype had been polluted.
Exploitation
Step 1: confirm the source
With the fragment payload accepted, the console check showed the prototype was polluted. Reading the JavaScript then identified the function responsible, and the author reports that absolutely no filters were in place in it. The input could still have passed through filters before reaching that function, but in this case it did not.
Step 2: find a sink
Pollution alone is not enough. The next step was to find a property that the application uses dangerously. In the source code, the key-value pair injected through the URL is used as an attribute-value pair inside a style tag. That is the gadget: a property the attacker controls is written into markup without filtering.
Step 3: chain to DOM XSS
Since the injected pair becomes an attribute and its value in a style tag, the exploit is simply an event handler as the attribute and JavaScript as the value:
#__proto__[onload]=alert(%22XSS by zhero_%22)
This chained the prototype pollution to an XSS. The author notes that any more elaborate JavaScript could be injected in the same way, and that alert was used only as a proof of concept.
Root cause
The source is a URL-processing function with no filters in place, so a key such as __proto__ reaches the prototype and sets a property on it. The WAF blocked the query-string attempts, but the fragment payload passed without a problem.
The gadget is the code that takes the injected key-value pair and writes it as an attribute and value inside a style tag. Because the value is not filtered or sanitised at that point, an event handler attribute with a JavaScript value executes. The report does not show the function or the template, so the exact merge and rendering code is not available here.
Impact
The result is DOM XSS: script chosen by the attacker runs in the context of the vulnerable page. The author frames the pollution itself as not directly exploitable and only useful once chained, which matches the definition quoted from PortSwigger at the start of the write-up.
Fix
Based on the described cause, the fix belongs in two places: the URL-processing function should reject or strip dangerous keys such as __proto__ and constructor before merging, and the code that writes the key-value pair into the style tag should not place attacker-controlled strings into attribute position without validation. Relying on the WAF alone is not sufficient, since the fragment bypassed it.
Variants to test
- Try the same key in the query string and in the fragment, in both dot and bracket notation, for example
?__proto__.zhero=zheroand#__proto__[zhero]=zhero. A positive result is a console check showing the property set on the prototype. - Try nested keys that survive a single-pass sanitiser, such as
?__pro__proto__to__.zhero=zhero. A positive result is the same polluted prototype after the filter has run. - Try the constructor path,
constructor[prototype][zhero]=zhero, in both notations. A positive result is a property visible on the prototype of objects created afterwards. - Look for URL fragments in archived URLs for the target, as the author did. A positive result is a fragment that the application parses as parameters rather than as a plain anchor.
- Once a source works, search the JavaScript for places where a key-value pair from the URL is written into markup, especially as an attribute inside a tag. A positive result is an event handler attribute such as
onloadexecuting the supplied value.
Closing
The write-up ends with the author's thanks to readers and a link to a previous article, "Business logic flaw, the enemy of scanners". The Medium page also carries the usual app download links for iOS and Android:


What happened, in plain words
A security researcher was looking at a website and found a way to make the site's own JavaScript code behave in a way its authors did not intend. The trick is called prototype pollution, and on its own it usually does nothing visible. The researcher then found a second weakness in the same site and joined the two together, so that the pollution caused the browser to run JavaScript code chosen by the attacker. That second part is called DOM XSS (cross-site scripting that happens inside the page's own code).
The site was part of a private bug bounty program, so the author deliberately changed some details and calls the target www.example.com. The report does not name the product or the feature. It only says that while researching the site the author had already found several other issues (XSS, iframe injection), which suggested that user input was not always filtered correctly.
The key behaviour to understand is that the application reads the URL, including the part after the # character, and uses the values it finds there. That is what made the fragment a usable entry point for the pollution.
Some background first: what is JavaScript and what is an object?
A web page is built from three things: HTML (the structure and text), CSS (the appearance) and JavaScript (the behaviour). JavaScript is a programming language that runs inside your browser. It can read what you type, change the page, talk to servers, and so on. When something goes wrong in JavaScript, the page can do things the site owner never planned.
In JavaScript, almost everything is an object. An object is simply a collection of named values, called key-value pairs: a name (the key) and the thing it holds (the value). Think of a paper form: each field has a label (the key) and an entry (the value). The simplest way to write one looks like this:
let myObject = { prop1: "A simple string", prop2: 100, prop3: true}
Line by line:
let myObject =creates a new variable calledmyObject. A variable is a named box that holds something.{ ... }are the braces that mark the start and end of an object.prop1: "A simple string"is one key-value pair: the key isprop1, the value is the textA simple string.prop2: 100is a key whose value is the number 100.prop3: trueis a key whose value is the booleantrue(yes/no).
There are two ways to reach a value inside an object. The first is dot notation:
myObject.prop1 // -> will return "A simple string"
Here myObject.prop1 means "the value stored under the key prop1 in myObject". The comment after // is just a note for humans; the browser ignores it.
The second is bracket notation:
myObject['prop2'] // -> will return 100
Here the key is written as text inside square brackets. Both forms do the same job. The difference matters later, because a filter that blocks one form may not block the other.
Prototypes: the family tree of objects
Every object in JavaScript is linked to another object called its prototype. The prototype is like a parent: the object inherits the parent's methods and properties. A method is simply a function (a piece of code that does something) that belongs to an object. A property is a value that belongs to an object.
When you ask for a property, the JavaScript engine first looks on the object itself. If it is not there, it looks on the object's prototype, then on the prototype's prototype, and so on up the chain. This is called the prototype chain. It is a bit like asking a family member for a recipe: if they do not have it, they ask their parent, and so on.
When you create a new object, JavaScript automatically assigns it to one of its built-in prototypes depending on the type of the new object. For example, a piece of text (a string) gets the String prototype, which is why text has methods such as toLowerCase and toUpperCase that you never wrote yourself. Your object inherited them.
You can walk up the chain with this syntax (on most browsers):
myObject.__proto__.__proto__.__proto__
Line by line:
myObjectis your object..__proto__is a special key that points to the object's prototype (its parent).- The second
.__proto__goes to the parent's parent. - The third goes one level higher again.
The important point is that __proto__ works as both a getter (it lets you read the prototype) and a setter (it lets you change it). So if an attacker can make the application write a property through __proto__, they can change the prototype that many other objects inherit from. That is what "polluting the prototype" means: adding or overwriting a property on a shared parent, so that every object below it inherits the change.
What is prototype pollution?
The report quotes a definition from PortSwigger: prototype pollution is a JavaScript vulnerability that lets an attacker add arbitrary properties to global object prototypes, which may then be inherited by user-defined objects. Although it is often unexploitable on its own, it lets an attacker control properties of objects that would otherwise be inaccessible. If the application later handles an attacker-controlled property in an unsafe way, it can be chained with other vulnerabilities.
In plain words: pollution is rarely a bug by itself. It is more like slipping an extra instruction into a shared rulebook that everyone reads. Nothing happens until some other part of the code follows that instruction in a dangerous way.
For the chain to work, three things are needed:
- A source: any input that lets you poison prototype objects with arbitrary properties. In this case, the URL.
- A sink: a JavaScript function or DOM element that enables arbitrary code execution. The DOM (Document Object Model) is the browser's in-memory model of the page; a sink is a place where data gets used in a way that can run code.
- An exploitable gadget: any property that is passed into a sink without proper filtering or sanitisation. Sanitisation means cleaning input so dangerous characters or words are removed or neutralised.
The real case
The author was researching a site on a private program. Having already found XSS and iframe injection issues there, the author suspected that user input was not always correctly filtered. The question was whether prototype pollution could be delivered through the URL. If the filtering policy was lax, something interesting might be possible.
Step 1: the obvious attempt, stopped by the WAF
The first payload was the simplest one, putting __proto__ straight into the query string (the part of a URL after the ?):
?__proto__.zhero=zhero
Line by line:
?starts the query string, the part of the URL that carries parameters.__proto__.zherouses dot notation to say: go to the__proto__of the object, then set the keyzhero.=zherogives that key the valuezhero.
A WAF (Web Application Firewall) is a filter that sits in front of a website and blocks requests that look malicious. It blocked this one. Several further attempts, including ones going through the constructor, were also blocked systematically.
Step 2: bypass attempts
Two ideas were tried to get past the filter. The first assumes the input is not recursively sanitised, meaning the filter only cleans one pass and a nested __proto__ survives:
?__pro__proto__to__.zhero=zhero
Line by line:
- The key is written as
__pro__proto__to__, in case the input has not been recursively sanitised. .zhero=zherothen sets the keyzheroto the valuezhero, as before.
The second goes through the constructor, which is itself an object and therefore also inherits a prototype:
constructor[prototype][zhero]=zhero
Line by line:
constructoris a built-in property that points to the function that created the object.[prototype]uses bracket notation to reach that function's prototype.[zhero]=zherosets the keyzheroto the valuezhero.
The author notes that for each case both ways of accessing an object, dot notation and bracket notation, should be tested, because the difference can matter after a WAF bypass depending on how the URL and its parameters are processed. These attempts did not get through.
Step 3: moving to the fragment
Looking through the web archive (a service that keeps old copies of web pages) for the target, the author noticed that many URLs contained the # character followed by useful information. The part after # is called the fragment. Normally a fragment is just an anchor: it tells the browser to scroll to a section of the page, and browsers do not send it to the server. But if the application itself reads the fragment, then it becomes input the application must handle. The author reasoned that the function handling the URL and its parameters must take it into account, and moved the payload there:
#__proto__[zhero]=zhero
Line by line:
#starts the fragment.__proto__[zhero]uses bracket notation to reach the prototype and set the keyzhero.=zherogives it the valuezhero.
This request passed with no problem from the WAF. A small test in the browser console (the developer tool where you can type JavaScript and see results) confirmed that the prototype had been polluted.
Exploitation
Step 1: confirm the source
With the fragment payload accepted, the console check showed the prototype was polluted. Reading the JavaScript then identified the function responsible, and the author reports that absolutely no filters were in place in it. The input could still have passed through filters before reaching that function, but in this case it did not.
Step 2: find a sink
Pollution alone is not enough. The next step was to find a property that the application uses dangerously. In the source code, the key-value pair injected through the URL is used as an attribute-value pair inside a style tag. In HTML, a tag is a building block such as <style> or <img>, and an attribute is a setting written inside the tag, such as src or onload. A style tag holds CSS rules. If attacker-controlled text lands in attribute position there without filtering, that is the gadget.
Step 3: chain to DOM XSS
Since the injected pair becomes an attribute and its value in a style tag, the exploit is simply an event handler as the attribute and JavaScript as the value:
#__proto__[onload]=alert(%22XSS by zhero_%22)
Line by line:
#starts the fragment.__proto__[onload]sets the keyonloadon the prototype.onloadis an event handler: a special attribute that the browser runs as code when something happens, such as the page finishing loading.=alert(%22XSS by zhero_%22)gives it the valuealert(...).alertis a built-in browser function that shows a pop-up box.%22is the URL-encoded form of a double quote, so the browser decodes it back to".
This chained the prototype pollution to an XSS. The author notes that any more elaborate JavaScript could be injected in the same way, and that alert was used only as a proof of concept.
Why it worked
The source is a URL-processing function with no filters in place, so a key such as __proto__ reaches the prototype and sets a property on it. The WAF blocked the query-string attempts, but the fragment payload passed without a problem.
The gadget is the code that takes the injected key-value pair and writes it as an attribute and value inside a style tag. Because the value is not filtered or sanitised at that point, an event handler attribute with a JavaScript value executes. The report does not show the function or the template, so the exact merge and rendering code is not available here.
What the impact is
The result is DOM XSS: script chosen by the attacker runs in the context of the vulnerable page. The author frames the pollution itself as not directly exploitable and only useful once chained, which matches the definition quoted from PortSwigger at the start.
How to fix it
Based on the described cause, the fix belongs in two places: the URL-processing function should reject or strip dangerous keys such as __proto__ and constructor before merging, and the code that writes the key-value pair into the style tag should not place attacker-controlled strings into attribute position without validation. Relying on the WAF alone is not sufficient, since the fragment bypassed it.
Variants to test
- Try the same key in the query string and in the fragment, in both dot and bracket notation, for example
?__proto__.zhero=zheroand#__proto__[zhero]=zhero. A positive result is a console check showing the property set on the prototype. - Try nested keys that survive a single-pass sanitiser, such as
?__pro__proto__to__.zhero=zhero. A positive result is the same polluted prototype after the filter has run. - Try the constructor path,
constructor[prototype][zhero]=zhero, in both notations. A positive result is a property visible on the prototype of objects created afterwards. - Look for URL fragments in archived URLs for the target, as the author did. A positive result is a fragment that the application parses as parameters rather than as a plain anchor.
- Once a source works, search the JavaScript for places where a key-value pair from the URL is written into markup, especially as an attribute inside a tag. A positive result is an event handler attribute such as
onloadexecuting the supplied value.
Closing
The write-up ends with the author's thanks to readers and a link to a previous article, "Business logic flaw, the enemy of scanners". The Medium page also carries the usual app download links for iOS and Android:


Glossary
- API: a defined way for one piece of software to ask another for data or actions, like a menu of requests a program accepts.
- Attribute: a setting written inside an HTML tag, such as
srcoronload. - Boolean: a value that is either true or false.
- Bracket notation: reaching a property by writing its key in square brackets, as in
myObject['prop2']. - Constructor: the built-in property that points to the function that created an object.
- CSS: the language that describes how a page looks (colours, layout, fonts).
- DOM: the browser's in-memory model of the page, which JavaScript can read and change.
- DOM XSS: cross-site scripting where the malicious code is placed into the page by the page's own JavaScript rather than by the server's HTML.
- Dot notation: reaching a property by writing a dot and the key, as in
myObject.prop1. - Event handler: an attribute such as
onloadwhose value the browser runs as code when an event happens. - Fragment: the part of a URL after
#; normally used to scroll to a section, and not sent to the server by the browser. - Gadget: in this context, a property that is passed into a sink without proper filtering, making the pollution exploitable.
- Getter / setter: code that reads (getter) or changes (setter) a value;
__proto__acts as both. - HTML: the language that describes the structure and text of a web page.
- Iframe injection: inserting an
<iframe>element (an embedded page inside a page) where it should not be possible. - JavaScript: the programming language that runs in the browser and makes pages interactive.
- Key-value pair: a name and the value stored under it, as in
prop1: "A simple string". - Method: a function that belongs to an object.
- Object: a collection of key-value pairs in JavaScript.
- Parameter: a named value carried in a URL, usually after
?or in the fragment. - Property: a value that belongs to an object.
- Prototype: the parent object that an object inherits properties and methods from.
- Prototype chain: the sequence of prototypes an object inherits from, one after another.
- Prototype pollution: adding or overwriting properties on a shared prototype so that other objects inherit the change.
- Query string: the part of a URL after
?that carries parameters. - Sanitisation: cleaning input so dangerous characters or words are removed or neutralised.
- Sink: a place in code where data is used in a way that can run code.
- Source: in this context, an input that lets an attacker poison prototype objects.
- String: a piece of text in JavaScript.
- Style tag: an HTML tag that holds CSS rules.
- Tag: a building block of HTML, such as
<style>or<img>. - URL encoding: writing special characters in a URL as
%plus a code, such as%22for a double quote. - Variable: a named box in a program that holds a value.
- WAF: Web Application Firewall, a filter in front of a website that blocks requests that look malicious.
- Web archive: a service that keeps old copies of web pages and their URLs.
- XSS: cross-site scripting, a bug where an attacker's JavaScript runs in another user's browser on a site.