← Blog

Claude MCP skill prototype pollution — deep-merge plugin configuration and theme override — SA-SKL-DESER6

Prototype pollution through deep-merge operations remains a persistent threat in MCP skill registry configuration systems. When users customize plugin behavior, theme appearance, or webhook configuration through nested JSON objects, the deep-merge code that applies those customizations often traverses the entire object graph — including the __proto__ key. SA-SKL-DESER6 covers four prototype pollution vectors: the deepmerge npm package, the subtle interaction between fast-deep-equal and merge, URL query parameter theme parsing via qs, and JSON Merge Patch (RFC 7396) without key filtering.

By SkillAudit  |  12 Nov 2026
SA-SKL-DESER6 findings at a glance
CRITICALDESER6-001 — deepmerge(pluginDefaults, userPluginConfig) traverses __proto__ in nested objects; attacker payload {"hooks":{"__proto__":{"debugMode":true}}} mutates Object.prototype process-wide; all subsequent if (config.debugMode) checks return true for every request
HIGHDESER6-002 — fast-deep-equal used to compare incoming config against stored config before merging; equality check passes for objects containing __proto__ as an own property but the subsequent deepmerge call mutates Object.prototype; fix: validate before comparison, not after
HIGHDESER6-003 — Theme override via URL query param parsed by qs with allowPrototypes: true; ?theme[__proto__][adminBanner]=true pollutes Object.prototype; every admin-banner check returns true for all users in that worker process
HIGHDESER6-004 — JSON Merge Patch (RFC 7396) applied to config object without filtering __proto__ and constructor keys; {"__proto__":{"isAdmin":true}} is a syntactically valid JSON Merge Patch that pollutes Object.prototype.isAdmin

DESER6-001 — deepmerge plugin config __proto__ traversal

The deepmerge npm package performs a recursive merge of two objects. Its default behavior traverses every key in the source object, including __proto__. When a user submits a plugin configuration object containing a __proto__ key — either directly or nested within a hooks or settings sub-object — deepmerge assigns to Object.prototype. The assignment persists for the life of the Node.js worker process and affects every object created after the mutation. If the polluted key is a flag like debugMode, isAdmin, or bypassRateLimit, every subsequent request runs with that flag set.

Vulnerable
// DESER6-001 — VULNERABLE
// deepmerge traverses __proto__ — user plugin config mutates Object.prototype.

import deepmerge from 'deepmerge';

const pluginDefaults = {
  hooks: { onInstall: null, onUninstall: null },
  settings: { timeout: 30000, retries: 3 },
};

router.post('/api/skills/:skillId/plugin-config', authenticate, async (req, res) => {
  const userConfig = req.body; // Attacker sends: { "hooks": { "__proto__": { "isAdmin": true } } }

  // VULNERABLE: deepmerge recursively traverses __proto__ key
  // Object.prototype.isAdmin is now true for all objects in this process
  const merged = deepmerge(pluginDefaults, userConfig);

  await db.savePluginConfig(req.params.skillId, merged);
  res.json({ ok: true });
  // Subsequent: if (req.user.isAdmin) → true for ALL users
});
Fixed
// DESER6-001 — FIXED
// Validate with Zod schema before merging — schema strips unknown keys including __proto__.
// Use deepmerge with isMergeableObject to prevent prototype chain traversal.

import deepmerge from 'deepmerge';
import { z } from 'zod';

const PluginConfigSchema = z.object({
  hooks: z.object({
    onInstall: z.string().url().nullable().optional(),
    onUninstall: z.string().url().nullable().optional(),
  }).optional(),
  settings: z.object({
    timeout: z.number().int().min(1000).max(120000).optional(),
    retries: z.number().int().min(0).max(10).optional(),
  }).optional(),
});

const DANGEROUS_KEYS = new Set(['__proto__', 'constructor', 'prototype']);

const safeIsMergeableObject = (val) =>
  typeof val === 'object' && val !== null &&
  !Object.keys(val).some(k => DANGEROUS_KEYS.has(k));

router.post('/api/skills/:skillId/plugin-config', authenticate, async (req, res) => {
  // Fix 1: Zod parse strips unknown/unexpected keys — __proto__ not in schema
  const parsed = PluginConfigSchema.safeParse(req.body);
  if (!parsed.success) return res.status(400).json({ error: parsed.error.format() });

  // Fix 2: deepmerge with isMergeableObject guard rejects objects with dangerous keys
  const merged = deepmerge(pluginDefaults, parsed.data, {
    isMergeableObject: safeIsMergeableObject,
  });

  await db.savePluginConfig(req.params.skillId, merged);
  res.json({ ok: true });
});

Why prototype pollution persists across requests: When Object.prototype.isAdmin is set to true, every plain object in that V8 heap inherits the property via the prototype chain. This includes request objects, response objects, and any configuration objects created after the mutation. The only recovery is to restart the worker process — and in a cluster, every worker that processed the malicious request is compromised until restart. The first request to trigger the attack poisons the process; every subsequent request runs poisoned. For related deserialization patterns in Redis pub/sub and BullMQ, see SA-SKL-DESER4.

DESER6-002 — fast-deep-equal comparison before mutating merge

fast-deep-equal is a popular npm package for deeply comparing two objects — commonly used to detect whether a config update actually changed anything before writing to the database. The subtle issue: fast-deep-equal compares own properties, including __proto__ as an own property (when the object is created with JSON.parse in some V8 edge cases or via Object.create(null) with explicit property assignment). The comparison may return false (not equal) for the attacker's payload, which looks like a legitimate change — causing the code to proceed with the merge. The merge then mutates Object.prototype. The equality check creates a false sense of security: "we only merge if something changed" does not mean "we validate before merging."

Vulnerable
// DESER6-002 — VULNERABLE
// fast-deep-equal comparison does not prevent prototype pollution in the subsequent merge.

import equal from 'fast-deep-equal';
import deepmerge from 'deepmerge';

router.put('/api/skills/:skillId/config', authenticate, async (req, res) => {
  const stored = await db.getSkillConfig(req.params.skillId);
  const incoming = req.body;

  // VULNERABLE: equality check doesn't validate structure — only skips the merge if unchanged
  // Attacker sends a new __proto__ payload — equal() returns false (it IS different from stored)
  if (equal(stored, incoming)) {
    return res.json({ ok: true, changed: false }); // no-op
  }

  // Proceeds to merge — __proto__ payload mutates Object.prototype
  const merged = deepmerge(stored, incoming);
  await db.saveSkillConfig(req.params.skillId, merged);
  res.json({ ok: true, changed: true });
});
Fixed
// DESER6-002 — FIXED
// Validate structure BEFORE equality comparison.
// If validation passes, incoming data is safe to merge.

import equal from 'fast-deep-equal';
import { z } from 'zod';

const SkillConfigSchema = z.object({
  displayName: z.string().max(100).optional(),
  description: z.string().max(2000).optional(),
  tags: z.array(z.string().max(50)).max(10).optional(),
  settings: z.object({
    isPublic: z.boolean().optional(),
    allowForks: z.boolean().optional(),
    minGradeRequired: z.enum(['A', 'B', 'C', 'D', 'F']).optional(),
  }).strict().optional(), // .strict() rejects unknown keys
}).strict();

router.put('/api/skills/:skillId/config', authenticate, async (req, res) => {
  // Fix: validate FIRST — Zod strips unknown keys, rejects __proto__
  const parsed = SkillConfigSchema.safeParse(req.body);
  if (!parsed.success) return res.status(400).json({ error: parsed.error.format() });

  const stored = await db.getSkillConfig(req.params.skillId);

  // Now safe to compare — parsed.data is a clean, validated object
  if (equal(stored, parsed.data)) {
    return res.json({ ok: true, changed: false });
  }

  // Safe to merge — no __proto__ or constructor keys in parsed.data
  const merged = { ...stored, ...parsed.data };
  await db.saveSkillConfig(req.params.skillId, merged);
  res.json({ ok: true, changed: true });
});

DESER6-003 — Theme override via qs bracket notation in URL query param

The qs library parses URL query strings with support for bracket notation: ?theme[color]=dark&theme[font]=mono produces { theme: { color: 'dark', font: 'mono' } }. By default, qs explicitly protects against prototype pollution by ignoring __proto__ keys. However, some integrations pass allowPrototypes: true or use older versions of qs without the protection. When a MCP skill registry allows theme customization via query string — to let authors preview their skill page with custom branding — an attacker can craft ?theme[__proto__][adminBanner]=true to pollute Object.prototype.adminBanner in the worker process. Every page rendered after this request shows the admin banner to all users.

Vulnerable
// DESER6-003 — VULNERABLE
// qs with allowPrototypes:true (or old qs version) — theme query param pollutes __proto__.

import qs from 'qs';

app.get('/skills/:skillId/preview', (req, res) => {
  // VULNERABLE: allowPrototypes:true in older qs integrations
  // Attacker URL: /skills/abc/preview?theme[__proto__][adminBanner]=true
  const params = qs.parse(req.url.split('?')[1], { allowPrototypes: true });

  const theme = params.theme ?? {};
  // theme.__proto__.adminBanner = true → Object.prototype.adminBanner = true
  // Every subsequent if ({}.adminBanner) check returns true for all users

  renderSkillPreview(res, params.skillId, theme);
});
Fixed
// DESER6-003 — FIXED
// Parse theme as a flat string enum — never as a nested object.
// Never pass user query param values directly into object merge operations.

const ALLOWED_THEMES = new Set(['light', 'dark', 'high-contrast', 'ocean', 'forest']);

app.get('/skills/:skillId/preview', (req, res) => {
  // Fix 1: use req.query (Express built-in) which uses qs with allowPrototypes:false (default)
  // Fix 2: validate theme as a flat enum string — never nested object
  const rawTheme = req.query.theme;
  const theme = typeof rawTheme === 'string' && ALLOWED_THEMES.has(rawTheme)
    ? rawTheme
    : 'light'; // Default on invalid input — never use user value as object key

  // Fix 3: if nested theme object is a product requirement, validate with Zod strict schema
  // const ThemeSchema = z.object({ color: z.enum(['dark','light']), font: z.enum(['mono','sans']) }).strict();
  // Never spread or deepmerge unvalidated query param objects

  renderSkillPreview(res, req.params.skillId, theme);
});

Audit all qs.parse() calls for allowPrototypes: true: Run grep -r "allowPrototypes" --include="*.js" --include="*.ts" . in your codebase. Any occurrence with true is a potential prototype pollution vector. Also check the qs version — versions before 6.7.0 had the prototype pollution protection disabled by default. The fix for new code is straightforward: parse theme and other appearance parameters as flat string enums, never as nested objects from query strings.

DESER6-004 — JSON Merge Patch without dangerous-key filtering

JSON Merge Patch (RFC 7396) is a standard for partially updating a JSON resource: the client sends a subset of the resource's fields, and the server merges them into the stored copy. Many MCP skill registry APIs implement PATCH endpoints using JSON Merge Patch. The issue is that RFC 7396 specifies that any JSON key is valid in a merge patch — including __proto__, constructor, and prototype. A naive merge patch implementation that calls Object.assign(storedConfig, patchObject) or spreads the patch ({ ...stored, ...patch }) will assign to Object.prototype when the patch contains __proto__ as a top-level key. This is because Object.assign treats __proto__ as a property assignment to the target's prototype, not as an own-key assignment.

Vulnerable
// DESER6-004 — VULNERABLE
// JSON Merge Patch via Object.assign — __proto__ in patch pollutes Object.prototype.

router.patch('/api/skills/:skillId/config', authenticate, async (req, res) => {
  const patch = req.body;
  // Attacker sends: { "__proto__": { "isAdmin": true } }
  // This is valid JSON — JSON.parse produces an object with __proto__ as own property

  const stored = await db.getSkillConfig(req.params.skillId);

  // VULNERABLE: Object.assign with __proto__ own property in source
  // This calls Object.defineProperty on the target's prototype chain
  const updated = Object.assign({}, stored, patch);
  // Object.prototype.isAdmin === true for all objects in this process now

  await db.saveSkillConfig(req.params.skillId, updated);
  res.json({ ok: true });
});
Fixed
// DESER6-004 — FIXED
// Strip dangerous keys before applying JSON Merge Patch.
// Use structuredClone (Node.js 17+) for safe deep cloning without prototype leakage.

const DANGEROUS_KEYS = new Set(['__proto__', 'constructor', 'prototype']);

function sanitisePatch(obj) {
  if (typeof obj !== 'object' || obj === null || Array.isArray(obj)) return obj;
  return Object.fromEntries(
    Object.entries(obj)
      .filter(([k]) => !DANGEROUS_KEYS.has(k))
      .map(([k, v]) => [k, sanitisePatch(v)]) // Recurse into nested objects
  );
}

router.patch('/api/skills/:skillId/config', authenticate, async (req, res) => {
  const rawPatch = req.body;

  // Fix 1: strip __proto__, constructor, prototype from patch and all nested objects
  const safePatch = sanitisePatch(rawPatch);

  // Fix 2: validate sanitized patch with Zod schema
  const parsed = SkillConfigPatchSchema.safeParse(safePatch);
  if (!parsed.success) return res.status(400).json({ error: parsed.error.format() });

  const stored = await db.getSkillConfig(req.params.skillId);

  // Fix 3: use structuredClone + spread — structuredClone does not copy prototype pollution
  const updated = { ...structuredClone(stored), ...parsed.data };

  await db.saveSkillConfig(req.params.skillId, updated);
  res.json({ ok: true });
});

Use structuredClone over JSON.parse(JSON.stringify()) for deep cloning: The old JSON.parse(JSON.stringify(obj)) round-trip technique does prevent __proto__ propagation because JSON serialization skips inherited properties. But structuredClone (available in Node.js 17+ and all modern browsers) is faster, handles circular references, and preserves typed arrays and Dates correctly. Prefer structuredClone for config object deep copies. For related prototype pollution patterns via lodash.merge and Object.assign, see SA-SKL-DESER5.

How SkillAudit detects SA-SKL-DESER6

SkillAudit's deserialization scanner applies four AST-level checks for the SA-SKL-DESER6 family:

PatternRoot causeFixSeverity
DESER6-001deepmerge traverses __proto__ in nested objects from user plugin configZod strict schema pre-validation; deepmerge isMergeableObject guardCRITICAL
DESER6-002fast-deep-equal comparison before merge — equality ≠ validation; __proto__ still mergesValidate with Zod BEFORE equality comparison; use spread not deepmergeHIGH
DESER6-003qs with allowPrototypes:true parses URL theme param as nested __proto__ objectParse theme as flat string enum; audit all qs.parse() allowPrototypes usagesHIGH
DESER6-004JSON Merge Patch via Object.assign — __proto__ own property in RFC 7396 patchsanitisePatch() strips dangerous keys recursively; validate with Zod; use structuredCloneHIGH