Testing Strategy
Relevant source files
The following files were used as context for generating this wiki page:PPScan is a browser extension designed to detect client-side Prototype Pollution vulnerabilities. Its testing strategy is divided into two main methodologies: a non-intrusive "Passive Mode" for analyzing scripts against known patterns, and an "Active Mode" that injects payloads to proactively find vulnerabilities. The extension also includes a manual mode for brute-forcing specific gadgets. This multi-faceted approach aims to identify vulnerabilities, particularly those in URL location parsers, by observing their effect on the JavaScript Object.prototype.
System Architecture
The extension is composed of several key components that work together to implement the testing strategy. The manifest.json file defines the structure, permissions, and entry points for these components.
The following diagram illustrates the high-level architecture and interaction between the main components of the PPScan extension.
Component Roles
| Component | Description | Source Files |
|---|---|---|
background.js | The main background process. It manages state, handles passive scanning setup, listens for findings from content scripts, and modifies HTTP headers in active mode. | scripts/background.js |
content_script.js | Injected into all web pages. It initiates active scanning and manual brute-forcing by creating iframes and injecting checker scripts. | scripts/content_script.js |
popup.html/popup.js | The user interface. Allows the user to enable/disable testing modes and trigger manual scans. It interacts with chrome.storage to persist settings. | pages/popup.html, scripts/popup.js |
exp.js | The core exploit script. Loaded into a hidden iframe, it contains the payloads and gadgets and is responsible for creating new iframes/windows with polluted URLs. | scripts/exp.js, pages/iframe.html |
utils.js | Contains utility functions for passive scanning, including downloading a pattern database and matching patterns against script content. | scripts/utils.js |
manifest.json | Defines the extension's permissions (e.g., webRequest, storage, <all_urls>), registers the scripts, and declares web-accessible resources. | manifest.json |
Testing Modes
The extension's functionality is controlled via settings stored in chrome.storage, which can be modified through the popup UI.
| Setting | Description | Default Value | Source Files |
|---|---|---|---|
passive | Enables/disables Passive Mode scanning. | true | scripts/background.js:20-22 |
toggle | Enables/disables Active Mode scanning. | false | scripts/background.js:17-19 |
buster | Enables "Window Mode" for Active Mode to handle frame-busting. Only available when Active Mode is on. | false | scripts/background.js:17-19, scripts/popup.js:30-39 |
Passive Mode
Passive mode scans JavaScript files requested by the browser for code patterns indicative of prototype pollution vulnerabilities. It does not modify the target page or its requests.
The flow for passive scanning is as follows:
- On startup, if
passivemode is enabled,background.jscallsupdateDB(). updateDB()inutils.jsdownloads a pattern database from/database.csv.- A listener is attached to
chrome.webRequest.onCompletedfor all script requests. - When a script finishes loading, the
scan()function is triggered. scan()downloads the script's content and passes it topatternMatch().patternMatch()iterates through the database patterns (regex or text) and checks for a match in the script content.- If a match is found, the finding is logged and the browser action badge count is incremented.
Sources: scripts/background.js:81-83, scripts/utils.js:40-49, 73-86
This diagram shows the passive scanning workflow.
Active Mode
Active Mode attempts to pollute Object.prototype by injecting payloads into the URL. It is more intrusive and modifies HTTP headers to bypass security policies like CSP and X-Frame-Options.
When toggle is set to true:
- The
content_script.jsinjects a hidden iframe (pages/iframe.html) into the current page. This iframe loadsscripts/exp.js. - The content script posts a message (
foo: "bar") to the iframe, containing the page's URL. exp.jsreceives the message and iterates through a list ofPAYLOADS. For each payload, it creates a new hidden iframe, setting itssrcto the target URL with the prototype pollution payload appended as a query parameter or a hash fragment.- Simultaneously,
content_script.jsinjects a checker script into the main page that periodically checks ifObject.prototypehas been polluted with specific properties (e32a5ec9c99ora0def12bce). - If pollution is detected, a
PPLogcustom event is dispatched. The content script listens for this event and sends the URL tobackground.js, which logs the finding.
Sources: scripts/content_script.js:77-92, 95-100, scripts/exp.js:72-91, scripts/background.js:6-10
Active Mode Payloads
The active scan cycles through a predefined set of payloads to test different pollution vectors.
| Name | Payload Parameter | Payload Value |
|---|---|---|
| XSS Prototype #3 | __proto__[e32a5ec9c99] | ddcb362f1d60 |
| XSS Prototype #4 | __proto__.e32a5ec9c99 | ddcb362f1d60 |
Sources: scripts/exp.js:3-8
Window Mode (Frame-Busting)
If the buster flag is enabled, exp.js will use window.open() instead of creating an iframe. This is designed to bypass sites that use frame-busting techniques, allowing the test to run in a new top-level window.
Sources: scripts/exp.js:73-80, scripts/popup.js:30-39
Manual Gadget Brute-forcing
The user can manually trigger a brute-force attack using a list of known gadgets from the popup UI. This is useful for testing if a confirmed pollution can be escalated to a cross-site scripting (XSS) vulnerability.
The following sequence diagram shows the manual brute-force flow.
The GADGETS array in exp.js contains numerous payloads designed to trigger debugger statements if a library is vulnerable.
Example Gadgets:
var GADGETS = [
'__proto__[innerHTML]=<img/src/onerror=debugger>',
'__proto__[context]=<img/src/onerror%3ddebugger>&__proto__[jquery]=x',
'__proto__[url][]=data:,debugger//&__proto__[dataType]=script',
'__proto__[srcdoc][]=<script>debugger</script>',
"__proto__[v-if]=_c.constructor('debugger')()",
// ... and many more
];
Sources: scripts/exp.js:10-49