Contributing Guide
Relevant source files
The following files were used as context for generating this wiki page:PPScan is a browser extension designed to scan for client-side Prototype Pollution vulnerabilities. It operates in two primary modes: a passive mode that analyzes scripts for vulnerable code patterns, and an active mode that attempts to inject payloads to confirm vulnerabilities. This guide provides a technical overview of the extension's architecture and functionality to help new contributors understand the codebase.
The extension is built around a background script for core logic, a content script for interacting with web pages, and a browser action popup for user control.
Sources: README.md, manifest.json
Project Architecture
The extension's structure is defined in manifest.json. It orchestrates the different JavaScript files and HTML pages, granting them the necessary permissions to function.
Sources: manifest.json
Core Components
| Component | File(s) | Description |
|---|---|---|
| Manifest | manifest.json | Defines the extension's structure, permissions, and entry points. |
| Background Scripts | pages/background.html, scripts/background.js, scripts/utils.js | Manages state, handles network requests, coordinates passive scanning, and manages results. |
| Content Script | scripts/content_script.js | Injected into all web pages (<all_urls>) to enable active scanning and communication with the page's DOM. |
| Browser Action | pages/popup.html, scripts/popup.js | Provides the user interface for controlling the extension's modes and viewing results. |
| Payload Delivery | pages/iframe.html, scripts/exp.js | An iframe and script combination used to deliver active scan payloads and gadgets without polluting the main window's context directly. |
Sources: manifest.json, pages/background.html:8-9, scripts/content_script.js:31-33
Component Interaction Diagram
This diagram illustrates how the components defined in manifest.json relate to each other.
Passive Scanning Mode
Passive mode, enabled by default, scans loaded JavaScript files for patterns indicative of prototype pollution vulnerabilities. It does not modify requests or actively inject payloads.
Sources: scripts/background.js:33-35, scripts/utils.js
Passive Scan Flow
The process begins when the passive flag is enabled in storage. The updateDB function is called, which downloads a list of patterns. A listener on chrome.webRequest.onCompleted then triggers a scan for every completed script request.
Contributing to Passive Mode
To improve passive scanning, you can add new vulnerability signatures to the database.csv file. Each line in this file represents a pattern to match.
The format is name|type|chunk:
- name: A descriptive name for the vulnerability (e.g.,
jQuery.extend). - type: The match type, either
regexortext. - chunk: The regular expression or plain text string to search for in script files.
Sources: scripts/utils.js:46-60
Active Scanning Mode
Active mode attempts to exploit potential prototype pollution vulnerabilities by injecting payloads into the URL. This mode is more intrusive and is controlled via the popup UI. It can be run in a standard iframe or a new window ("Window Mode") to bypass frame-busting mechanisms.
Sources: scripts/popup.js:13-24, scripts/content_script.js:31-33, README.md:21-23
Active Scan Flow (Standard)
The active scan is initiated from the content script, which creates a hidden iframe (pages/iframe.html). This iframe loads scripts/exp.js, which then receives the target URL via postMessage and proceeds to inject payloads into new iframes.
Brute-force Gadgets
The "Brute Gadgets" feature allows manual triggering of gadget testing against the current page. It uses a predefined list of common post-pollution gadgets to attempt exploitation (e.g., causing a debugger statement to execute).
Contributing to Active Mode
New payloads and gadgets can be added to scripts/exp.js.
PAYLOADS: Used for the initial check to see if prototype pollution is possible. These are simple key-value pairs designed to polluteObject.prototype.// file: scripts/exp.js:5-9 var PAYLOADS = [ ['XSS Prototype #3', '__proto__[e32a5ec9c99]', 'ddcb362f1d60', ], ['XSS Prototype #4', '__proto__.e32a5ec9c99', 'ddcb362f1d60', ], ];GADGETS: These are full query strings or hash values that exploit a polluted prototype to achieve a result, like XSS.// file: scripts/exp.js:12-14 var GADGETS = [ '__proto__[innerHTML]=<img/src/onerror=debugger>', '__proto__[context]=<img/src/onerror%3ddebugger>&__proto__[jquery]=x', '__proto__[url][]=data:,debugger//&__proto__[dataType]=script', ];
Sources: scripts/exp.js:5-9, 12-49
User Interface and Controls
The main user interface is the browser action popup, defined in pages/popup.html. Its logic is handled by scripts/popup.js, which communicates with the background script to manage settings and display results.
| Control | ID | Function |
|---|---|---|
| Toggle Active Mode | toggle | Enables/disables the active scanning feature. Toggling on also shows the "Window Mode" button. |
| Enable Window Mode | buster | When active mode is on, this switches payload injection from an iframe to a new window. Useful for sites with frame-busting. |
| Toggle Passive Mode | passive | Enables/disables the passive, pattern-matching scanner. |
| Brute Gadgets (Search) | brute | Triggers a brute-force test using gadgets from exp.js in the URL's search parameters. |
| Brute Gadgets (Hash) | brutehash | Triggers a brute-force test using gadgets from exp.js in the URL's hash. |
| Clear | clear | Clears all stored findings. |
Sources: pages/popup.html:49-68, scripts/popup.js:8-73
Results and Logging
Vulnerabilities found by both active and passive modes are stored in a Set named found within the background script to prevent duplicates. The badge on the extension icon is updated with the count of unique findings.
The popup requests the list of found items from the background script and displays them in a table.