Claude skill prototype pollution via URL query string parsing — SA-SKL-PROTOTYPE7
Prototype pollution via URL query strings is one of the oldest and most reliably exploitable server-side JavaScript vulnerabilities — and it keeps reappearing in MCP skill deployments because the default configuration of the qs library, which Express uses under the hood for query string parsing, does not block __proto__ keys by default in older project setups. SA-SKL-PROTOTYPE7 covers four distinct injection paths: direct qs.parse without allowPrototypes:false; the Express default query parser inheriting the same flaw and poisoning a CORS origin check; a custom mergeDeep function without hasOwnProperty guards merging user JSON; and a Redis cache read that Object.assigns a previously poisoned payload onto request objects, persisting the pollution for the lifetime of the Node.js process.
Prototype pollution via query string parsing in MCP skill deployments
The qs library supports nested object syntax in query strings: ?user[name]=alice parses to { user: { name: 'alice' } }. The same mechanism accepts ?__proto__[admin]=true, which without allowPrototypes: false writes to Object.prototype.admin. Because every plain JavaScript object inherits from Object.prototype, any subsequent property lookup obj.admin on any object in the same process returns "true" — including req.user.admin used in an authorization check. The vulnerability is process-wide and persists until the Node.js worker restarts. MCP skill servers are typically long-running processes that handle many requests before restarting, making the blast radius of a single prototype pollution write very broad. SA-SKL-PROTOTYPE7 covers all four common injection paths observed in audit engagements.
qs.parse("__proto__[admin]=true") without allowPrototypes:false; sets Object.prototype.admin = "true" on all objects; req.user.admin truthy check passes for all subsequent requests__proto__ without filtering; CORS origin check uses Object property lookup; poisoned to reflect all origins for all requestsmergeDeep({}, JSON.parse(userInput)) without hasOwnProperty check; {"__proto__": {"isAdmin": true}} in body poisons prototype process-wideJSON.parse() of Redis cache value then Object.assign(target, parsed); cache was previously poisoned by prototype pollution write; pollution persists process lifetimePROTOTYPE7-001 — qs.parse without allowPrototypes:false sets Object.prototype.admin
The qs library's nested object parsing uses bracket notation to build deep objects from flat query string keys. When a key path traverses __proto__, qs writes directly to Object.prototype unless the allowPrototypes: false option is set. An attacker sends a single request with the query string ?__proto__[admin]=true. After that request is processed, every plain object in the Node.js process inherits admin: "true" from Object.prototype. Any route that checks if (req.user.admin) will now pass for all users — including unauthenticated ones — because the property lookup walks the prototype chain. The URLSearchParams API is immune because it does not support nested object notation at all and returns flat string values.
// VULNERABLE — qs.parse without allowPrototypes:false; __proto__ written to Object.prototype
import qs from 'qs';
// Attacker sends: GET /api/skill?__proto__[admin]=true
app.get('/api/skill', (req, res) => {
// VULNERABLE: qs.parse is called internally by Express, or directly here
const params = qs.parse(req.query); // allowPrototypes defaults to false in qs >= 6.7
// but older project lock files pin qs < 6.7 where the default was true
});
// After the above request, anywhere in the process:
const user = {}; // fresh plain object
console.log(user.admin); // "true" — prototype was polluted
if (req.user.admin) {
// ALWAYS passes after pollution — attacker gains admin for all requests
return grantAdminAccess(req, res);
}
// FIXED — explicit allowPrototypes:false; or use URLSearchParams for flat params
import qs from 'qs';
// Option 1: use qs with allowPrototypes explicitly disabled
app.get('/api/skill', (req, res) => {
const params = qs.parse(req.url.split('?')[1] || '', {
allowPrototypes: false, // blocks __proto__, constructor, prototype keys
allowDots: false, // also disable dot notation if not needed
depth: 3, // limit nesting depth
});
// params.__proto__ is undefined — Object.prototype not modified
});
// Option 2: URLSearchParams for flat query parameters (no nested object support)
app.get('/api/skill', (req, res) => {
const url = new URL(req.url, 'http://localhost');
const filter = url.searchParams.get('filter'); // flat string; no nesting
const page = url.searchParams.get('page');
// __proto__ is treated as a literal string key, not a prototype write
});
PROTOTYPE7-002 — Express default query parser poisons CORS origin check
Express configures qs as its default query string parser via req.query. When a request arrives, Express calls qs.parse(queryString) and assigns the result to req.query. If the installed version of qs does not default to allowPrototypes: false, or if the application has not overridden the query parser, the same __proto__ pollution path is available through any GET request. A particularly dangerous interaction occurs when the CORS origin check uses an object property lookup for the allowlist — for example, const allowed = { 'https://skillaudit.dev': true }; if (allowed[origin]). After prototype pollution sets Object.prototype['https://attacker.com'] = true, the CORS check passes for the attacker's origin on all subsequent requests, turning a prototype pollution write into a full CORS bypass.
// VULNERABLE — Express default qs parser; CORS check uses object property lookup
import express from 'express';
const app = express();
// CORS allowlist implemented as object property lookup (common pattern)
const CORS_ALLOWED = { 'https://skillaudit.dev': true, 'https://app.skillaudit.dev': true };
app.use((req, res, next) => {
const origin = req.headers.origin;
// VULNERABLE: if attacker poisoned Object.prototype['https://evil.com'] = true,
// then CORS_ALLOWED['https://evil.com'] resolves truthy via prototype chain
if (origin && CORS_ALLOWED[origin]) {
res.setHeader('Access-Control-Allow-Origin', origin);
res.setHeader('Access-Control-Allow-Credentials', 'true');
}
next();
});
// Any GET route uses Express default qs parser — attacker sends:
// GET /api/audits?__proto__[https://evil.com]=true HTTP/1.1
// After this request, CORS_ALLOWED['https://evil.com'] is truthy for all requests
// FIXED — override Express query parser with allowPrototypes:false; use Set for CORS allowlist
import express from 'express';
import qs from 'qs';
const app = express();
// Override the default query parser on the Express app
app.set('query parser', str => qs.parse(str, {
allowPrototypes: false,
depth: 3,
}));
// Use a Set for the CORS allowlist — Set.has() does not walk prototype chain
const CORS_ALLOWED = new Set(['https://skillaudit.dev', 'https://app.skillaudit.dev']);
app.use((req, res, next) => {
const origin = req.headers.origin;
// Set.has() is immune to prototype pollution — only checks own entries
if (origin && origin !== 'null' && CORS_ALLOWED.has(origin)) {
res.setHeader('Access-Control-Allow-Origin', origin);
res.setHeader('Access-Control-Allow-Credentials', 'true');
res.setHeader('Vary', 'Origin');
}
next();
});
PROTOTYPE7-003 — Custom mergeDeep without hasOwnProperty guard
Many MCP skill deployments include a custom deep merge utility used to combine default configuration with user-supplied overrides. These utilities are frequently written without a hasOwnProperty guard, meaning they will write to __proto__ if it appears as a key in the source object. When user input is parsed with JSON.parse and passed directly to mergeDeep, an attacker can send a JSON body containing {"__proto__": {"isAdmin": true}}. The merge function recurses into __proto__ and sets properties on Object.prototype. Even lodash.merge was vulnerable to this pattern before version 4.17.21 — audits should verify the lockfile version. The safe alternatives are structuredClone() for deep copy of untrusted data, or a merge function that explicitly checks Object.prototype.hasOwnProperty.call(src, key) and skips __proto__, constructor, and prototype keys.
// VULNERABLE — mergeDeep without hasOwnProperty check; __proto__ written to Object.prototype
function mergeDeep(target, source) {
for (const key in source) {
// VULNERABLE: 'in' operator includes prototype chain; no hasOwnProperty check;
// no __proto__ key guard
if (source[key] && typeof source[key] === 'object') {
target[key] = target[key] || {};
mergeDeep(target[key], source[key]); // recurses into __proto__
} else {
target[key] = source[key];
}
}
return target;
}
app.post('/api/config', express.json(), (req, res) => {
const defaults = { theme: 'dark', pageSize: 20 };
// Attacker sends: {"__proto__": {"isAdmin": true}}
const config = mergeDeep({}, req.body); // Object.prototype.isAdmin = true after this
res.json(config);
});
// FIXED — structuredClone for deep copy; lodash.merge >= 4.17.21; explicit key guard
import merge from 'lodash/merge.js'; // ensure lockfile has >= 4.17.21
// Option 1: structuredClone — does not write to prototype chain; safe for untrusted input
app.post('/api/config', express.json(), (req, res) => {
const defaults = { theme: 'dark', pageSize: 20 };
// structuredClone produces a deep copy without touching Object.prototype
const userConfig = structuredClone(req.body);
// Then merge using lodash.merge (patched >= 4.17.21) — safe from prototype pollution
const config = merge({}, defaults, userConfig);
res.json(config);
});
// Option 2: custom merge with explicit prototype-key guard
function safeMergeDeep(target, source) {
if (!source || typeof source !== 'object') return target;
for (const key of Object.keys(source)) { // Object.keys = own enumerable only
// Explicitly block prototype pollution keys
if (key === '__proto__' || key === 'constructor' || key === 'prototype') continue;
if (source[key] && typeof source[key] === 'object' && !Array.isArray(source[key])) {
target[key] = target[key] && typeof target[key] === 'object' ? target[key] : {};
safeMergeDeep(target[key], source[key]);
} else {
target[key] = source[key];
}
}
return target;
}
PROTOTYPE7-004 — Object.assign from poisoned Redis cache onto request objects
MCP skill servers frequently cache serialized user session data in Redis to avoid repeated database queries. The common pattern is to store the session as a JSON string, retrieve it on each request, parse it with JSON.parse, and then merge the properties onto a target object using Object.assign(target, parsed). If the Redis cache was previously written with a poisoned payload — either through a prototype pollution write that serialized __proto__ properties into a JSON string, or through a direct cache injection — then Object.assign will copy those properties onto the target. Because prototype pollution is process-wide and persists until the Node.js process restarts, a single poisoned cache entry can affect all requests handled by the same worker. The fix is to never Object.assign cache data directly; instead extract only the expected fields by name into a fresh object.
// VULNERABLE — Object.assign from JSON-parsed Redis cache; propagates poisoned __proto__ keys
import { createClient } from 'redis';
const redis = createClient();
app.use(async (req, res, next) => {
const sessionId = req.cookies.sid;
if (!sessionId) return next();
const cached = await redis.get(`session:${sessionId}`);
if (!cached) return next();
// VULNERABLE: JSON.parse may produce an object with __proto__ key if cache was poisoned;
// Object.assign copies all own enumerable properties — but if the cached string was
// produced from a polluted object, __proto__ can appear as a string key
// More critically: if previous prototype pollution wrote to Object.prototype and that
// was captured in a JSON.stringify call with a replacer that includes inherited props
const parsed = JSON.parse(cached);
Object.assign(req, parsed); // VULNERABLE: merges all keys from cache onto req
next();
});
// FIXED — explicit field extraction; never Object.assign from cache onto req or res
app.use(async (req, res, next) => {
const sessionId = req.cookies.sid;
if (!sessionId) return next();
const cached = await redis.get(`session:${sessionId}`);
if (!cached) return next();
let parsed;
try {
parsed = JSON.parse(cached);
} catch {
return next(); // invalid JSON in cache — skip; do not crash
}
// Extract only the specific fields expected in a valid session — never spread all keys
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
req.session = {
userId: typeof parsed.userId === 'string' ? parsed.userId : null,
orgId: typeof parsed.orgId === 'string' ? parsed.orgId : null,
roles: Array.isArray(parsed.roles) ? parsed.roles.filter(r => typeof r === 'string') : [],
issuedAt: typeof parsed.issuedAt === 'number' ? parsed.issuedAt : 0,
};
// __proto__, constructor, prototype, and any unexpected keys are simply not copied
}
next();
});
Related patterns: Earlier prototype pollution vectors from npm package merge utilities and Express body-parser are covered in SA-SKL-PROTOTYPE6. For server-side request forgery that can be chained with prototype pollution to reach internal metadata endpoints, see SA-SKL-SSRF10. The SA-SKL-INJECTION5 page covers NoSQL operator injection, which shares the JSON body parsing attack surface with PROTOTYPE7-003.
| Finding | Severity | Vulnerable pattern | Fix |
|---|---|---|---|
PROTOTYPE7-001 | High | qs.parse without allowPrototypes:false; __proto__[admin]=true sets Object.prototype.admin; auth bypass for all requests | qs.parse(str, { allowPrototypes: false }); or use URLSearchParams for flat params |
PROTOTYPE7-002 | High | Express default qs parser; CORS allowlist uses object property lookup; prototype pollution turns CORS check into allow-all | app.set('query parser', str => qs.parse(str, { allowPrototypes: false })); use Set.has() for allowlist |
PROTOTYPE7-003 | High | Custom mergeDeep without hasOwnProperty guard; {"__proto__": {"isAdmin": true}} in body poisons prototype | structuredClone() for untrusted input; lodash.merge >= 4.17.21; merge with explicit __proto__ key guard |
PROTOTYPE7-004 | Medium | Object.assign(req, JSON.parse(redisCache)); previously poisoned cache propagates pollution onto all request objects | Extract only named expected fields from parsed cache; never Object.assign from cache directly onto req or res |