Architecture Overview
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 architecture is composed of several key scripts that work together to provide two primary scanning methods: a passive, signature-based scan of loaded scripts, and an active, payload-based scan that attempts to pollute the Object.prototype of the visited page.
The extension's core components include a background script for central logic and state management, a content script injected into web pages for active scanning and DOM interaction, a popup interface for user control, and dedicated scripts for payload delivery and utility functions. Communication between these components is handled through a mix of standard Chrome extension APIs, including message passing, storage, and event listeners.
Core Components
The extension is modular, with each script or file serving a distinct purpose as defined in the manifest.
This diagram shows the high-level interaction between the main components of the PPScan extension.
Sources: manifest.json, scripts/popup.js, scripts/background.js, scripts/content_script.js
Manifest (manifest.json)
The manifest.json file is the entry point of the extension, defining its capabilities, permissions, and script registrations.
| Key | Description |
|---|---|
permissions | Requests broad permissions including tabs, storage, <all_urls>, webRequest, and webRequestBlocking to monitor and modify network traffic and interact with all pages. |
background | Registers background.html (which loads background.js and utils.js) as the persistent background script. |
content_scripts | Injects content_script.js into all frames on all URLs (<all_urls>). |
web_accessible_resources | Exposes pages/iframe.html and scripts/exp.js so they can be loaded by content scripts within the context of a web page. |
browser_action | Defines pages/popup.html as the UI for the extension's toolbar button. |
Sources: manifest.json:5-32
Background Script (background.js)
The background script acts as the central controller. Its primary responsibilities include:
- State Management: Initializes and maintains the set of found vulnerabilities (
found). It also sets default values fortoggle(Active Mode),buster(Window Mode), andpassive(Passive Mode) inchrome.storage.syncon installation. - Communication Hub: Listens for connections from the popup (
chrome.extension.onConnect) to send vulnerability data and clear logs. It also listens for messages from the content script (chrome.runtime.onMessage) reporting active scan findings. - Badge UI: Updates the browser action badge count using
setBadgeCountto reflect the number of detected vulnerabilities. - Header Modification: If Active Mode is enabled, it uses the
webRequestAPI to modifyContent-Security-PolicyandX-Frame-Optionsheaders to facilitate testing. - Passive Scan Initiation: If Passive Mode is enabled, it triggers the database download and sets up the network listener via
updateDB()fromutils.js.
Sources: scripts/background.js:4-70, scripts/utils.js:120-126
Content Script (content_script.js)
This script is injected directly into web pages and is the primary actor for the Active Scanning mode.
- Listens for Triggers: It sets up event listeners (
TriggerBrute,TriggerBruteHash) that are dispatched frompopup.jsto initiate a scan. - Iframe Orchestration: Upon triggering, it creates a hidden
iframethat loadspages/iframe.html. This iframe is used as a sandbox to send scanning payloads without directly reloading the main page. It communicates with the iframe's content viapostMessage. - Pollution Checker: It injects a script into the page's DOM that periodically checks if
Object.prototypehas been polluted with specific test properties (e32a5ec9c99,a0def12bce). - Reporting: If pollution is detected, the injected script dispatches a
PPLogcustom event. The content script listens for this event and forwards the URL of the vulnerable page to the background script usingchrome.runtime.sendMessage.
Sources: scripts/content_script.js:1-115
Popup (popup.js & popup.html)
The popup provides the user interface for controlling the extension and viewing results.
- Mode Toggles: Contains buttons to enable/disable Active Mode, Passive Mode, and Window Mode. These buttons update configuration values in
chrome.storage.sync. - Scan Triggers: The "Search" and "Hash" buttons execute a small script in the active tab to dispatch the
TriggerBruteandTriggerBruteHashcustom events, respectively, which are caught by thecontent_script.js. - Results Display: On load, it connects to the background script to request the list of found vulnerabilities and dynamically populates a table in
popup.html. It also provides a "Clear" button to empty the log.
Sources: pages/popup.html:43-76, scripts/popup.js:5-76
Scanning Modes
PPScan operates in two distinct modes, which can be enabled or disabled from the popup UI.
Active Scanning
Active scanning attempts to find prototype pollution vulnerabilities by injecting payloads into the URL. This process is initiated by the user from the popup and involves coordination between the content script and a dedicated payload script running in an iframe.
The flow is as follows:
- User clicks "Search" or "Hash" in the popup.
popup.jsexecutes a script in the active tab, dispatching aTriggerBruteorTriggerBruteHashevent.content_script.jscatches the event and creates a hidden iframe loadingiframe.html.content_script.jssends the current page's URL to the iframe viapostMessage.- The iframe's script,
exp.js, receives the URL. It iterates through a list ofGADGETSpayloads. - For each gadget,
exp.jscreates another iframe, setting itssrcto the target URL with the gadget payload appended to the search parameters or hash. - Simultaneously,
content_script.jshas injected a checker into the main page that monitorsObject.prototypefor changes. - If a payload successfully pollutes the prototype, the checker detects it and sends the finding to
background.js.
This diagram illustrates the sequence of events during an active scan.
Sources: scripts/popup.js:60-66, scripts/content_script.js:1-23, scripts/exp.js:41-65
Payloads (exp.js)
The exp.js script contains the logic for the active scan. It defines two main sets of payloads:
PAYLOADS: A smaller set used for initial detection, pairing a parameter name with a value (e.g.,__proto__[e32a5ec9c99]=ddcb362f1d60).GADGETS: A larger list of known gadget strings that can lead to XSS or other impacts when a prototype pollution vulnerability is present. These are used for the brute-force scan.
Sources: scripts/exp.js:1-39
Passive Scanning
Passive scanning operates in the background, inspecting the content of JavaScript files as they are loaded by the browser. It relies on a database of known vulnerable patterns.
The flow is as follows:
- If "Passive Mode" is enabled,
background.jscallsupdateDB()on startup. utils.jsfetches a pattern database from/database.csv.- Once the database is loaded, a listener is attached to
chrome.webRequest.onCompletedfor all script requests. - For each completed script request, the
scanfunction inutils.jsis called. - The
scanfunction downloads the script's content. - The
patternMatchfunction compares the script content against regex or text patterns from the database. - If a match is found, the vulnerability details (domain, type, file location) are added to the
foundset inbackground.js, and the badge is updated.
This diagram shows the process flow for the passive scanning mode.
Sources: scripts/background.js:72-74, scripts/utils.js:44-70, 96-126
State and Configuration
The extension's operational state is managed through chrome.storage.sync and in-memory variables in the background script.
| Storage Key | File | Purpose | Default |
|---|---|---|---|
toggle | popup.js, background.js | Controls Active Scanning mode and header modifications. | false |
buster | popup.js, exp.js | Enables "Window Mode" for active scanning to bypass frame busting. | false |
passive | popup.js, background.js | Controls Passive Scanning mode. | true |
Sources: scripts/background.js:47-58, scripts/popup.js:12-58
The primary runtime data, the set of found vulnerabilities, is stored in the found constant in background.js. This data is persisted only for the current browser session and can be cleared via the popup UI.
Sources: scripts/background.js:4, 20-24