Express Prototype Pollution Gadgets
Last updated
Last updated
Learn & practice AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE) Learn & practice GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
For further details take a look to the original reserach
In an Express app using a JSON content type response and reflecting a JSON:
In these cases XSS isn't normally possible with a JSON content type. However, with prototype pollution we can confuse Express to serve up an HTML response. This vulnerability relies on the application using res.send(obj)
and using the body parser with the application/json content type.
By polluting body
and _body
properties, it's possible to cause Express to serve up the HTML content type and reflect the _body
property, resulting in stored XSS.
It's possible to make express render UTF-7 content with:
The following PP will make attributes inside a JSON to have an extra space which won't break the functionality:
Then a reflected JSON will looks like:
The following PP gadget will make the server send back the HTTP header: Access-Control-Expose_headers: foo
It requires the CORS module to be installed
With the following payload, it's possible to hide a method from an OPTIONS response:
It's possible to change the returned status code using the following PP payload:
When you assign to a prototype with a primitive such as a string, it produces a no-op operation since the prototype has to be an object. If you attempt to assign a prototype object to the Object.prototype
itself, this will throw an exception. We can use these two behaviours to detect if prototype pollution was successful:
When an application includes an object in its response, creating an attribute with an unusual name alongside __proto__
can be insightful. Specifically, if only the unusual attribute is returned in the response, this could indicate the application's vulnerability:
Moreover, in scenarios where a library like Lodash is employed, setting a property both via prototype pollution (PP) and directly inside the object offers another diagnostic approach. If such a property is omitted from the response, it suggests that Lodash is verifying the existence of the property in the target object before merging:
There is an option in Express that allows you to create objects from query string parameters. You could definitely use it in a bug chain to exploit a prototype pollution vulnerability.
?foo.bar=baz
create an object in Node.
Learn & practice AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE) Learn & practice GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)