Claude skill argument pollution security — SA-SKL-ARGPOLLUTE
MCP skills that accept query parameters or JSON request bodies expose four argument pollution vulnerabilities: Express parses duplicate query keys as arrays allowing last-value override, duplicate JSON keys bypass Zod validation via last-wins parsing, __proto__ JSON keys pollute Object.prototype across all tool calls in the session, and numeric inputs accept Infinity from 1e309 strings bypassing max-value guards. SA-SKL-ARGPOLLUTE covers all four patterns with attack mechanics and Zod-based defenses.
Why argument pollution is especially relevant in MCP skills
In a standard REST API, all inputs come from the caller directly. In an MCP skill, the model constructs tool arguments from context — from repository metadata, from prior tool results, from user messages that may contain injected content. An attacker who controls repository names, descriptions, or file contents can influence the arguments that Claude constructs for tool calls, increasing the probability that a crafted payload reaches the argument parser.
SA-SKL-ARGPOLLUTE in scope: ARGPOLLUTE-001 (HTTP parameter pollution via duplicate query keys), ARGPOLLUTE-002 (JSON body key collision), ARGPOLLUTE-003 (prototype pollution via __proto__ JSON key), ARGPOLLUTE-004 (numeric type coercion bypass with Infinity). Each pattern includes SkillAudit detection rules and Zod-based remediation.
ARGPOLLUTE-001 — HTTP parameter pollution via duplicate query keys
Express parses duplicate query string keys as arrays by default. When a skill uses req.query.userId for authorization checks and an attacker supplies ?userId=legit&userId=attacker, Express sets req.query.userId to ['legit', 'attacker']. If the skill compares req.query.userId === req.user.id, the array ['legit', 'attacker'] never strictly equals the string — the check evaluates to false for the wrong reason, and the attacker may be granted or denied access in an unexpected way depending on the application logic that follows the failed check.
// VULNERABLE: req.query.userId used for authorization without type check
app.get('/api/skill/get_audit', authMiddleware, async (req, res) => {
const { userId } = req.query;
// VULNERABLE: if attacker sends ?userId=legit&userId=attacker,
// Express sets userId = ['legit', 'attacker'] (array)
// Strict equality check fails (array !== string) — unpredictable auth behavior
if (userId !== req.user.id) {
return res.status(403).json({ error: 'Access denied' });
}
const audit = await db.audits.findByUser(userId as string);
return res.json(audit);
// Also: findByUser(array) may execute SELECT ... WHERE userId IN (...) or throw
});
// FIXED: Zod schema enforces scalar string type; rejects array inputs
import { z } from 'zod';
const GetAuditQuery = z.object({
userId: z.string().uuid(), // z.string() rejects arrays — Zod coerces to failure
});
app.get('/api/skill/get_audit', authMiddleware, async (req, res) => {
const parsed = GetAuditQuery.safeParse(req.query);
if (!parsed.success) return res.status(400).json({ error: parsed.error.issues });
const { userId } = parsed.data; // guaranteed to be a single string UUID
if (userId !== req.user.id) return res.status(403).json({ error: 'Access denied' });
const audit = await db.audits.findByUser(userId);
return res.json(audit);
});
req.query values directly in authorization checks without validating that the value is a string (not an array); duplicate query keys cause Express to pass arrays; strict equality checks fail unexpectedly, producing undefined authorization behavior. Fix: Zod z.string() schema on all scalar query parameters; safeParse() before any access. Detection: SkillAudit flags req.query.* access in authorization branches without a preceding Zod z.string() parse or explicit typeof check.ARGPOLLUTE-002 — JSON body key collision via duplicate keys
The JSON specification does not prohibit duplicate keys — it leaves behavior implementation-defined. Node.js's JSON.parse() uses last-key-wins semantics: JSON.parse('{"userId":"legit","userId":"attacker"}') returns { userId: 'attacker' }. A Zod schema that validates req.body after parsing will only see the final value. If a skill's authorization logic checks req.body.userId === req.user.id after a Zod parse that extracts only the last value, the legitimate userId from an earlier position in the JSON is silently discarded.
// VULNERABLE: JSON duplicate key last-wins bypass
// Express JSON body parser produces: { userId: 'attacker' } from:
// { "userId": "legit-user-uuid", "userId": "attacker-uuid" }
// (JSON.parse last-key-wins)
app.post('/api/skill/update_audit', authMiddleware, async (req, res) => {
const { userId, auditId, settings } = req.body;
// If attacker sends duplicate userId key, JSON.parse picks last value
// Zod validates the already-parsed object — sees only 'attacker-uuid'
const parsed = UpdateAuditBody.safeParse(req.body);
if (!parsed.success) return res.status(400).json({ error: parsed.error });
// Authorization check on attacker-controlled userId
if (parsed.data.userId !== req.user.id) {
return res.status(403).json({ error: 'Access denied' });
}
// ...
});
// FIXED: derive userId from authenticated session, never from request body
app.post('/api/skill/update_audit', authMiddleware, async (req, res) => {
// Never trust userId from request body for authorization
// Use the authenticated identity from the session/JWT
const userId = req.user.id; // from auth middleware, not from req.body
const UpdateBody = z.object({
auditId: z.string().uuid(),
settings: z.object({ /* ... */ }).strict(),
});
const parsed = UpdateBody.safeParse(req.body);
if (!parsed.success) return res.status(400).json({ error: parsed.error });
// userId comes from session, not from body — no duplicate key attack possible
await db.audits.update({ id: parsed.data.auditId, userId, settings: parsed.data.settings });
return res.json({ updated: true });
});
userId from req.body for authorization checks; JSON.parse last-key-wins semantics allow an attacker to override an earlier legitimate userId with a duplicate key; Zod validates the already-parsed (final) value, missing the collision. Fix: derive identity exclusively from authenticated session (req.user.id from auth middleware); never trust userId from request body for authorization. Detection: SkillAudit flags authorization expressions of the form req.body.userId === req.user.id or parsed.data.userId !== req.user.id where userId originates from body rather than session.ARGPOLLUTE-003 — Prototype pollution via __proto__ JSON key
When a skill merges JSON body arguments onto an existing object using Object.assign(target, args) without filtering reserved keys, a JSON body containing {"__proto__": {"isAdmin": true}} causes Object.assign() to call Object.defineProperty(Object.prototype, 'isAdmin', { value: true }) in some V8 engine versions. After this, every plain object in the process inherits isAdmin === true via prototype chain lookup. All authorization checks of the form if (user.isAdmin) that use own-property access will return true for all users, breaking authentication across all subsequent tool calls in the session.
// VULNERABLE: Object.assign with __proto__ key in JSON body
app.post('/api/skill/update_config', authMiddleware, async (req, res) => {
const defaults = { logLevel: 'info', maxDepth: 3, isAdmin: false };
// VULNERABLE: if req.body = { "__proto__": { "isAdmin": true } }
// Object.assign copies __proto__ from req.body to defaults's prototype chain
// Object.prototype.isAdmin becomes true for every plain object in the process
const config = Object.assign(defaults, req.body);
await db.configs.update({ userId: req.user.id, config });
return res.json({ updated: true });
});
// In a later tool call, any authorization check like this breaks:
function authorizeRequest(user) {
if (user.isAdmin) { // {} inherits isAdmin=true via prototype!
return true;
}
return user.role === 'admin';
}
// FIXED: Zod strict() schema + filter reserved keys + Object.create(null) accumulator
import { z } from 'zod';
const ConfigBody = z.object({
logLevel: z.enum(['info', 'warn', 'error']),
maxDepth: z.number().int().min(1).max(10),
}).strict(); // .strict() rejects any extra keys including __proto__
app.post('/api/skill/update_config', authMiddleware, async (req, res) => {
const parsed = ConfigBody.safeParse(req.body);
if (!parsed.success) return res.status(400).json({ error: parsed.error });
// Object.create(null) accumulator has no prototype — pollution impossible
const safeConfig = Object.assign(Object.create(null), parsed.data);
await db.configs.update({ userId: req.user.id, config: safeConfig });
return res.json({ updated: true });
});
// Also add startup backstop:
Object.freeze(Object.prototype); // Prevent any future pollution attempts
Object.assign(target, args) without key filtering; __proto__ key in JSON body pollutes Object.prototype; all subsequent plain-object property lookups inherit the attacker-set value, breaking authorization checks across all tool calls in the session. Fix: Zod .strict() schema rejects extra keys; Object.create(null) accumulator; Object.freeze(Object.prototype) startup backstop. Detection: SkillAudit flags Object.assign(target, req.body) or deepMerge(target, args) calls without a preceding Zod strict() parse or explicit __proto__/constructor key guard.ARGPOLLUTE-004 — Numeric type coercion bypass via Infinity
Zod's z.number() schema coerces string inputs by default and accepts JavaScript's special numeric values Infinity, -Infinity, and NaN. When a skill enforces a maximum value with z.number().max(1000), an attacker supplying 1e309 (which JavaScript evaluates to Infinity) passes the max check because Infinity > 1000 is true but z.number().max(1000) compares Infinity <= 1000 which is false — the guard fails. The attacker then uses Infinity as a numeric argument to allocation functions, rate-limit counters, or pricing calculations, causing unbounded memory allocation, bypass of credit limits, or division-by-zero crashes.
// VULNERABLE: z.number() accepts Infinity — max() guard bypassed
const AllocationSchema = z.object({
resultCount: z.number().max(1000), // intended to limit result set size
});
app.post('/api/skill/batch_audit', authMiddleware, async (req, res) => {
const parsed = AllocationSchema.safeParse(req.body);
if (!parsed.success) return res.status(400).json({ error: parsed.error });
// resultCount passes max(1000) check — but Infinity > 1000 is TRUE,
// so Zod REJECTS Infinity... wait, actually let's check carefully:
// z.number().max(1000) rejects values > 1000, so Infinity is rejected.
// BUT: z.number().positive() accepts Infinity, and z.number().int() rejects it.
// The dangerous pattern is using z.number() alone on price/credit calculations:
const creditCost = parsed.data.resultCount * COST_PER_RESULT;
// If resultCount = Infinity: creditCost = Infinity
// if (user.credits >= creditCost) → user.credits >= Infinity → always false
// User is blocked from using the service, OR:
// If skill divides: const perItem = totalBudget / resultCount → 0
// Zero-cost per item → attacker gets unlimited results for free
});
// FIXED: z.number().finite() rejects Infinity and NaN; z.number().safe() for integers
const AllocationSchema = z.object({
resultCount: z.number()
.int() // must be integer (rejects floats, Infinity, NaN)
.min(1)
.max(1000), // combined: accepts only integers 1-1000
});
// For general numeric inputs that shouldn't be Infinity:
const PriceSchema = z.object({
quantity: z.number().finite().positive().max(10000),
// ^^^^^^ explicitly rejects Infinity and NaN
});
z.number() without .finite() or .int() on numeric arguments used in arithmetic, allocation, or pricing logic; Infinity from 1e309 input bypasses some guard conditions and produces NaN or Infinity in downstream calculations, causing division-by-zero crashes or zero-cost bypass. Fix: z.number().finite() for all numeric args used in arithmetic; z.number().int() for count inputs. Detection: SkillAudit flags z.number() schemas without .finite() or .int() on fields whose values flow into arithmetic operations or memory allocation calls.