What is Client-Side Prototype Pollution?
Relevant source files
The following files were used as context for generating this wiki page:PPScan is a browser extension designed as a "Client Side Prototype Pollution Scanner". Its primary function is to automatically detect potential Client-Side Prototype Pollution vulnerabilities in web applications. The extension operates by inspecting web traffic and actively probing the visited pages for weaknesses, with a specific focus on vulnerable location parsers. It provides different modes of operation, including passive analysis of scripts and active injection of payloads to confirm vulnerabilities.
The core architecture is a standard browser extension model, comprising background scripts for persistent logic, content scripts for interacting with web pages, and a browser action popup for user control. When a potential vulnerability is found, it is logged and displayed in the extension's popup, providing details about the affected domain and the location of the vulnerable code.
Sources: README.md, manifest.json
System Architecture
PPScan is composed of several key components that work together to identify prototype pollution vulnerabilities. The manifest.json file defines the relationships between these components, including background scripts, content scripts, and UI pages.
The diagram below illustrates the high-level architecture of the PPScan extension.
This diagram shows how the user's browsing activity triggers the content script, which in turn uses an iframe with exploit logic to test the page. Findings are reported back to the background script and displayed in the popup UI.
Sources: manifest.json, scripts/content_script.js:1-19, scripts/background.js
Scanning Modes
PPScan operates in two primary modes: Passive and Active. These modes can be toggled from the extension's popup.
Sources: pages/popup.html:47-56, scripts/popup.js:7-10
Passive Mode
Passive mode is enabled by default and works by scanning JavaScript files for known vulnerable patterns. When enabled, the background script adds a listener to chrome.webRequest.onCompleted for all script requests.
- The
updateDBfunction downloads a list of patterns from/database.csv. - For each completed script request, the
scanfunction is triggered. - The script's content is downloaded via
fetch. - The
patternMatchfunction searches the script's content for regular expressions or text chunks defined in the database. - If a match is found, the finding (domain, vulnerability type, file location) is added to the
foundset and the browser action badge is updated.
The following flowchart details the passive scanning process.
This flowchart shows the logic of the passive scanner, from listening for network requests to matching patterns and logging findings.
Sources: scripts/utils.js:84-91, scripts/background.js:75-77, scripts/utils.js:15-40
Active Mode
Active Mode directly tests the web page by injecting payloads that attempt to pollute Object.prototype. When enabled via the popup, the content_script.js becomes active.
- The content script injects an invisible
iframe(pages/iframe.html) into the current page. This iframe loadsscripts/exp.js. - The content script posts a message to the iframe containing the page's URL.
exp.jsreceives the message and, based on the message type, begins injecting payloads. It creates additional iframes, setting theirsrcto the target URL but with prototype pollution payloads appended to the search parameters or the hash.- A separate part of the content script continuously checks if
Object.prototypehas been polluted with specific test properties (e.g.,e32a5ec9c99). - If pollution is detected, a
PPLogcustom event is dispatched, which is then sent tobackground.jsto be recorded.
The sequence diagram below shows the interaction for Active Mode scanning.
This diagram illustrates the sequence of events in Active Mode, from user activation to payload injection and vulnerability detection.
Sources: scripts/content_script.js:23-113, scripts/exp.js:80-104, scripts/popup.js:11-23
Window Mode (Frame Busting)
A special "Window Mode" can be enabled for Active scanning. This is useful for applications that use frame-busting techniques, which would prevent the iframe-based testing from working. Instead of creating an iframe, this mode uses window.open() to launch the test URL in a new window.
Sources: README.md:23-25, scripts/exp.js:82-90, pages/popup.html:49
Payloads and Gadgets
The core of the active scanning and exploitation attempt lies in the payloads and gadgets defined in scripts/exp.js.
Detection Payloads
These payloads are used in the initial Active Mode scan to see if the page is vulnerable to pollution. They assign a specific key-value pair to __proto__.
| Payload Name | Parameter | Value |
|---|---|---|
| XSS Prototype #3 | __proto__[e32a5ec9c99] | ddcb362f1d60 |
| XSS Prototype #4 | __proto__.e32a5ec9c99 | ddcb362f1d60 |
Sources: scripts/exp.js:1-8
Gadget Brute-Forcing
If a page is suspected to be vulnerable, the user can trigger a "gadget brute-force" from the popup. This uses a more extensive list of known gadgets that can lead to Cross-Site Scripting (XSS) if a prototype pollution vulnerability exists. The process is similar to Active Mode, but it iterates through the GADGETS array, appending each one to the URL's search string or hash.
The buttons "Search" and "Hash" in the popup trigger this process for the URL's search parameters and hash respectively.
Sources: pages/popup.html:58-64, scripts/popup.js:60-69, scripts/content_script.js:1-19, [scripts/exp.js:47-78]
Example gadgets from the list:
var GADGETS = [
'__proto__[innerHTML]=<img/src/onerror=debugger>',
'__proto__[url][]=data:,debugger//&__proto__[dataType]=script',
'__proto__[srcdoc][]=<script>debugger</script>',
"__proto__[v-if]=_c.constructor('debugger')()",
'__proto__[onload]=debugger',
// ... and many more
];
Sources: [scripts/exp.js:10-45]
Vulnerability Reporting
When a vulnerability is found, either through passive or active scanning, the details are stored and presented to the user.
- Detection: A vulnerability is detected by
content_script.js(Active) orutils.js(Passive). - Logging: The finding is sent to
background.js. Active findings are sent viachrome.runtime.sendMessage, while passive findings are handled directly within the background page's context. - Storage:
background.jsadds a JSON string representing the finding to aSetnamedfoundto avoid duplicates. - Notification: The browser action's badge is updated with the total count of unique vulnerabilities.
- Display: When the user opens the popup,
popup.jsrequests the list of found items from the background script and dynamically builds a table to display the results.
| Column | Description |
|---|---|
| host | The hostname of the vulnerable page. Links to the domain. |
| type | The type of finding (e.g., 'Active Mode' or a library name from passive scan). |
| location | The full URL and line/column number where the vulnerability was found. |
Sources: scripts/background.js:7-12, 36-43, scripts/popup.js:74-87, pages/popup.html:67-75