Claude MCP skill prototype pollution via URL query string parsing and qs library — SA-SKL-PROTOTYPE9
URL query strings are the most common way to pass filter parameters, configuration overrides, and feature flags to MCP skill API endpoints. When these query strings are parsed with the qs library in its default configuration — or when URLSearchParams output is merged directly into JavaScript objects — an attacker can inject __proto__ keys that propagate up the prototype chain and corrupt the runtime state of the Node.js process. The impact ranges from privilege escalation (injecting isAdmin: true into every object in the process) to remote code execution via gadget chains in downstream libraries. SA-SKL-PROTOTYPE9 covers four prototype pollution vectors that arise specifically from URL query string parsing in MCP skill configuration and filter endpoints.
qs.parse("__proto__[isAdmin]=true") in qs <6.7.3 parses the __proto__ key directly into the parsed object's prototype; calling code that checks obj.isAdmin without a hasOwnProperty guard returns true for every object in the process after one attacker requestURLSearchParams output iterated and spread into a config object via Object.assign(config, Object.fromEntries(params)) — attacker sends ?__proto__[debug]=true; Object.fromEntries produces {"__proto__": {"debug": "true"}} which Object.assign merges into the config object's prototype chainqs); attacker sends GET /api/skills?__proto__[admin]=true&__proto__[role]=superuser; req.query contains a poisoned prototype that propagates to any object created in the same process during the request lifecycleJSON.parse()d without prototype sanitization; attacker sends ?filter=eyJfX3Byb3RvX18iOnsiYWRtaW4iOnRydWV9fQ== (base64 of {"__proto__":{"admin":true}}); no schema validation after parse allows prototype pollutionPROTOTYPE9-001 — qs.parse() with __proto__ key in qs <6.7.3
The qs library is the default query string parser in Express.js and is widely used in MCP skill config endpoints. Versions before 6.7.3 did not block __proto__ as a parsed key — when an attacker sends a request with ?__proto__[isAdmin]=true, qs.parse() creates the parsed object with obj.__proto__.isAdmin = "true", directly mutating Object.prototype. Any code that subsequently checks someObj.isAdmin without Object.prototype.hasOwnProperty.call(someObj, 'isAdmin') will find "true" on every plain object created in the process for the duration of that process's lifetime.
// VULNERABLE — PROTOTYPE9-001
// qs version: "qs": "^6.5.0" in package.json — vulnerable to __proto__ pollution.
// Attacker sends: GET /api/config?__proto__[isAdmin]=true
// After this request, every plain object in the process has isAdmin = "true" on its prototype.
import qs from 'qs';
app.get('/api/config', (req, res) => {
// VULNERABLE: qs.parse() on raw query string without allowPrototypes:false
const params = qs.parse(req.url.split('?')[1]);
// Later in authorization middleware — anywhere in the process:
const user = getUserFromSession(req);
// user.isAdmin is undefined on the user object itself, but attacker has set
// Object.prototype.isAdmin = "true" — this check passes for ANY user now:
if (user.isAdmin) {
return res.json({ config: getAdminConfig() }); // attacker gets admin config
}
});
// FIXED — PROTOTYPE9-001
// Fix 1: Upgrade qs to >=6.11.0 — blocks __proto__, constructor, prototype keys by default.
// Fix 2: If pinned to older qs, explicitly set allowPrototypes:false + allowDots:false.
// Fix 3: Use query parser: 'simple' in Express to bypass qs entirely for simple params.
import qs from 'qs'; // must be >=6.11.0
app.get('/api/config', (req, res) => {
// FIX 1: qs >=6.11.0 blocks __proto__ by default — also set explicitly for defense-in-depth
const params = qs.parse(req.url.split('?')[1], {
allowPrototypes: false, // FIX 2: explicit block even if qs version is old
allowDots: false, // prevent dot-notation prototype traversal
depth: 2, // limit nesting depth
});
// FIX 3: Validate parsed params against expected shape before use
const allowedKeys = new Set(['theme', 'locale', 'page', 'limit']);
const safeParams = Object.fromEntries(
Object.entries(params).filter(([k]) => allowedKeys.has(k))
);
const user = getUserFromSession(req);
if (user.isAdmin) { // now only truthy if user object itself has isAdmin
return res.json({ config: getAdminConfig() });
}
});
Detection: SkillAudit checks package.json for qs versions below 6.7.3 and scans for qs.parse() calls without the allowPrototypes: false option. It also checks whether the Express app configures a query parser explicitly or uses the default qs-based parser.
PROTOTYPE9-002 — URLSearchParams iterated and merged into config object
URLSearchParams is the browser-native and Node.js built-in query string API. When developers iterate over URLSearchParams and use Object.fromEntries(params) to convert the results into a plain JavaScript object, the string key __proto__ is treated as a literal key by Object.fromEntries — which then produces {"__proto__": {"debug": "true"}}. When this is passed to Object.assign(target, fromEntriesResult), Object.assign enumerates the source object and sets target.__proto__ = {"debug": "true"}, effectively replacing the target's prototype chain. This is a subtle variant that appears in code that migrated from qs to the native URL API expecting improved security.
// VULNERABLE — PROTOTYPE9-002
// URLSearchParams output converted with Object.fromEntries() — __proto__ key treated as literal.
// Attacker sends: GET /api/skill/filter?__proto__[debug]=true&__proto__[verbose]=1
// Object.fromEntries({ "__proto__": { "debug": "true", "verbose": "1" } })
// Object.assign(config, ...) then writes those values onto config's __proto__.
app.get('/api/skill/filter', (req, res) => {
const params = new URLSearchParams(req.url.split('?')[1]);
const defaults = { page: 1, limit: 20, sort: 'created_at' };
// VULNERABLE: Object.fromEntries() preserves __proto__ as a literal key name.
// Object.assign then merges it onto defaults' prototype chain.
const config = Object.assign(defaults, Object.fromEntries(params));
const skills = getSkills(config);
res.json({ skills });
});
// FIXED — PROTOTYPE9-002
// Fix 1: Never use Object.assign() or spread with untrusted URLSearchParams output.
// Fix 2: Allowlist-copy: only extract known, expected keys from URLSearchParams.
// Fix 3: Use Object.create(null) as merge target — no prototype chain to pollute.
app.get('/api/skill/filter', (req, res) => {
const params = new URLSearchParams(req.url.split('?')[1]);
// FIX 2: Allowlist-copy — only extract expected keys, never use Object.fromEntries on untrusted params
const ALLOWED = { page: Number, limit: Number, sort: String, category: String };
const config = Object.create(null); // FIX 3: null prototype — nothing to pollute
for (const [key, type] of Object.entries(ALLOWED)) {
if (params.has(key)) {
config[key] = type(params.get(key));
}
}
// Apply safe defaults
config.page = Math.max(1, config.page || 1);
config.limit = Math.min(100, config.limit || 20);
config.sort = ['created_at', 'name', 'rating'].includes(config.sort) ? config.sort : 'created_at';
const skills = getSkills(config);
res.json({ skills });
});
PROTOTYPE9-003 — Express default query parser exposes qs nested object parsing
Express.js uses qs as its default query string parser (the query parser: 'extended' setting). This means every Express application that has not explicitly set app.set('query parser', 'simple') parses query strings with qs. When qs is an older version or is not configured to block prototype keys, every route in the application is implicitly vulnerable. The attacker sends a single request to any endpoint with ?__proto__[admin]=true — the parsed req.query object contains a poisoned prototype that may persist in the process memory and affect subsequent requests if any middleware or route handler merges req.query into a persistent config or model object.
// VULNERABLE — PROTOTYPE9-003
// Express app with default query parser (qs extended mode) — no explicit allowPrototypes:false.
// Attacker sends: GET /api/skills?__proto__[role]=admin&__proto__[isStaff]=true
// req.query.__proto__ contains {role: "admin", isStaff: "true"}
// Any code that merges req.query or checks .role / .isStaff without hasOwnProperty is affected.
const express = require('express');
const app = express();
// No app.set('query parser', ...) — defaults to qs extended mode
app.get('/api/skills', async (req, res) => {
// req.query parsed by qs — if qs <6.7.3, __proto__ key pollutes Object.prototype
const filters = { ...req.query }; // spread copies enumerable keys including __proto__ side-effects
const results = await db.skills.find(filters);
res.json(results);
});
// FIXED — PROTOTYPE9-003
// Fix 1: Set query parser to 'simple' (Node.js querystring) — does not support nesting, no prototype risk.
// Fix 2: If extended parser is needed for nesting, pin qs >=6.11.0 and configure it.
// Fix 3: Validate req.query against schema before spreading into any object.
const express = require('express');
const app = express();
// FIX 1: Use simple query parser — no nested object support, no qs, no __proto__ risk
app.set('query parser', 'simple');
// OR: FIX 2 — custom qs parser with safe config if nested objects are needed
// app.set('query parser', (str) => qs.parse(str, { allowPrototypes: false, depth: 2, allowDots: false }));
app.get('/api/skills', async (req, res) => {
// FIX 3: Validate req.query against allowed schema before use
const page = Math.max(1, parseInt(req.query.page, 10) || 1);
const limit = Math.min(50, parseInt(req.query.limit, 10) || 20);
const category = typeof req.query.category === 'string' ? req.query.category : undefined;
const results = await db.skills.find({ category, page, limit });
res.json(results);
});
Detection: SkillAudit scans for Express apps that do not explicitly set the query parser option, and flags cases where req.query is spread or merged into plain objects without schema validation. It also checks the installed version of qs and flags versions below 6.7.3.
PROTOTYPE9-004 — Base64-encoded JSON filter parameter parsed without prototype sanitization
Some MCP skill APIs accept complex filter expressions as base64-encoded JSON query parameters to work around URL length limits and query string escaping constraints. The pattern ?filter=base64(JSON.stringify(filterObj)) is decoded and JSON.parse()d server-side. JSON.parse() in Node.js processes __proto__ as a literal key in the parsed object — it does not set Object.prototype.__proto__, but if the parsed result is subsequently passed to Object.assign(), _.merge(), or any deep-merge utility, those utilities will traverse the __proto__ key and mutate the prototype chain. The base64 encoding obscures the payload from naive WAF pattern matching.
// VULNERABLE — PROTOTYPE9-004
// Base64-decoded JSON filter parameter passed to deep-merge without schema validation.
// Attacker encodes: JSON.stringify({"__proto__": {"isAdmin": true}}) then base64-encodes it.
// ?filter=eyJfX3Byb3RvX18iOnsiaXNBZG1pbiI6dHJ1ZX19
// Server decodes + JSON.parses — result object has __proto__ as own key.
// If passed to _.merge() or lodash deep merge, prototype chain is poisoned.
import { merge } from 'lodash'; // lodash <4.17.21 or unpatched deep merge
app.get('/api/skills/search', (req, res) => {
const filterB64 = req.query.filter;
if (!filterB64) return res.json(await db.skills.find({}));
// VULNERABLE: no schema validation after JSON.parse
const filterObj = JSON.parse(Buffer.from(filterB64, 'base64').toString('utf8'));
const defaults = { active: true, limit: 20 };
// VULNERABLE: lodash merge traverses __proto__ key and sets Object.prototype.isAdmin = true
const query = merge(defaults, filterObj);
const results = await db.skills.find(query);
res.json(results);
});
// FIXED — PROTOTYPE9-004
// Fix 1: Schema validation after JSON.parse using zod or ajv — rejects unexpected keys.
// Fix 2: Never pass user-parsed JSON to lodash merge() or any deep-merge utility.
// Fix 3: Use Object.create(null) intermediate + allowlist-copy instead of merge().
// Fix 4: Upgrade lodash to >=4.17.21 (prototype pollution patch) if merge is unavoidable.
import { z } from 'zod';
const FilterSchema = z.object({
category: z.string().optional(),
minRating: z.number().min(0).max(5).optional(),
maxRating: z.number().min(0).max(5).optional(),
tags: z.array(z.string()).max(10).optional(),
active: z.boolean().optional(),
}).strict(); // .strict() rejects extra keys — including __proto__
app.get('/api/skills/search', async (req, res) => {
const filterB64 = req.query.filter;
if (!filterB64) return res.json(await db.skills.find({ active: true }));
let rawFilter;
try {
rawFilter = JSON.parse(Buffer.from(filterB64, 'base64').toString('utf8'));
} catch {
return res.status(400).json({ error: 'Invalid filter encoding' });
}
// FIX 1: Validate parsed filter against strict schema — rejects __proto__ key
const result = FilterSchema.safeParse(rawFilter);
if (!result.success) {
return res.status(400).json({ error: 'Invalid filter', details: result.error.flatten() });
}
// FIX 3: Build query from validated data, never from raw parsed object
const query = { active: result.data.active ?? true };
if (result.data.category) query.category = result.data.category;
if (result.data.minRating != null) query.rating = { $gte: result.data.minRating };
if (result.data.maxRating != null) query.rating = { ...(query.rating || {}), $lte: result.data.maxRating };
if (result.data.tags?.length) query.tags = { $in: result.data.tags };
const results = await db.skills.find(query);
res.json(results);
});
Summary — SA-SKL-PROTOTYPE9 at a glance
| Pattern | Root cause | Fix | Severity |
|---|---|---|---|
| PROTOTYPE9-001 | qs.parse() in qs <6.7.3 without allowPrototypes:false; __proto__ key parsed directly into Object.prototype; every plain object in the process inherits the injected property | Upgrade to qs >=6.11.0; set allowPrototypes:false, allowDots:false; validate parsed params against allowlist | Critical |
| PROTOTYPE9-002 | Object.fromEntries(urlSearchParams) + Object.assign() treats __proto__ as a literal key that Object.assign writes onto the target's prototype chain | Allowlist-copy known keys from URLSearchParams; use Object.create(null) as merge target; never spread untrusted URLSearchParams output | Critical |
| PROTOTYPE9-003 | Express default query parser (qs extended mode) without explicit safe configuration; every route implicitly vulnerable; req.query spread into persistent objects pollutes prototype chain | Set app.set('query parser', 'simple'); or configure custom qs parser with allowPrototypes:false; validate req.query before spread | High |
| PROTOTYPE9-004 | Base64-encoded JSON filter decoded + parsed with JSON.parse() then passed to lodash merge(); merge traverses __proto__ key; WAF-bypass via base64 encoding | Schema validation with zod.strict() after JSON.parse; never pass user JSON to lodash merge; upgrade lodash to >=4.17.21 | High |
Does your MCP skill's query string parsing code protect against prototype pollution?
SkillAudit scans for unsafe qs versions, unguarded Object.assign() calls on URLSearchParams output, unvalidated req.query spreads, and base64-JSON filter parameters passed to deep-merge utilities — before an attacker poisons your process's prototype chain.