Iframe vs. Window Mode Implementation
Relevant source files
The following files were used as context for generating this wiki page:PPScan employs two distinct operational modes for active prototype pollution scanning: the default Iframe Mode and a specialized Window Mode. The primary difference lies in the context used to load and test polluted URLs. Iframe Mode, as the name suggests, uses dynamically created <iframe> elements. Window Mode, however, opens a new browser window or tab. This dual-mode approach allows the scanner to adapt to different web application security postures, particularly those that implement frame-busting techniques.
The choice between these modes is controlled by the user through the extension's popup interface. Window Mode is specifically intended for scenarios where an application prevents itself from being embedded in an iframe, a common security measure known as frame busting.
Sources: README.md, scripts/exp.js:71-108
Mode Selection and Configuration
The user can toggle between Iframe and Window modes from the extension's popup menu. This action is managed by popup.js, which updates a boolean flag in chrome.storage.sync.
Sources: pages/popup.html:43-44, scripts/popup.js:25-34
Configuration Storage
The operational mode is determined by the buster key stored via the chrome.storage API.
| Key | Type | Default | Description |
|---|---|---|---|
toggle | Boolean | false | Master switch for "Active Mode". If false, neither Iframe nor Window mode scans will be initiated. The "Window Mode" button is only visible if this is true. |
buster | Boolean | false | Toggles between Iframe and Window mode. false (default) enables Iframe Mode. true enables Window Mode. This is set by the "Enable/Disable Window Mode" button. |
Sources: scripts/popup.js:7-34, scripts/background.js:23-28
The diagram below illustrates the user flow for enabling Window Mode.
This diagram shows the user interaction within the popup to enable Window Mode and set the corresponding storage flag. Sources: pages/popup.html:43-44, scripts/popup.js:7-34
Iframe Mode (Default)
When "Active Mode" is enabled and "Window Mode" is disabled (buster: false), PPScan operates in Iframe Mode. This is the standard scanning procedure.
Sources: scripts/exp.js:71-72, scripts/exp.js:84-108
Architecture and Flow
- The
content_script.json the target page injects a hidden iframe pointing topages/iframe.html. - Upon loading, the content script posts a message to this iframe containing the page's URL and a
foo: "bar"identifier. - The
exp.jsscript withiniframe.htmlreceives this message. It retrieves thebustersetting fromchrome.storage. - Since
busterisfalse, the script enters theelseblock and iterates through a predefined list ofPAYLOADS. - For each payload, it creates a new, nested
<iframe>element. Thesrcof this new iframe is the target URL appended with a prototype pollution payload, alternating between URL search parameters and the URL hash. - These nested iframes are appended to the document, loading the polluted URLs and allowing the content script in those frames to detect if
Object.prototypewas successfully polluted.
The following sequence diagram details the Iframe Mode process:
This diagram shows the message passing and iframe creation sequence for a standard Iframe Mode scan. Sources: scripts/content_script.js:80-92, scripts/exp.js:71-72, scripts/exp.js:84-108
Window Mode
Window Mode is activated when the user enables it in the popup (buster: true). Its purpose is to bypass frame-busting protections that would otherwise block the Iframe Mode.
Sources: README.md, scripts/exp.js:73-83
Architecture and Flow
- The initial steps are identical to Iframe Mode:
content_script.jsinjectsiframe.htmland posts thefoo: "bar"message. exp.jsreceives the message and retrieves thebustersetting.- Since
busteristrue, the script executeswindow.open(), loading the target URL in a new window or tab. - To prevent infinite recursion, a
dummysearch parameter is added to the URL, and the window is given a specific name (ppdeadbeef1win). - The
content_script.jsrunning in this new window detects thedummyparameter. It then initiates its own series of checks by manipulating the URL and reloading the page to test for pollution vulnerabilities. After a timeout, it closes itself.
The sequence diagram below illustrates the Window Mode activation:
This diagram shows how a message from the content script leads to the opening of a new window when Window Mode is active. Sources: scripts/content_script.js:80-92, scripts/exp.js:72-83
Frame-Busting Countermeasures
To support both modes, especially Iframe Mode, the extension actively modifies HTTP response headers to defeat common anti-framing security policies. When "Active Mode" is on, a listener in background.js intercepts web requests.
// File: scripts/background.js:33-49
chrome.webRequest.onHeadersReceived.addListener((response) => {
response.responseHeaders.forEach(header => {
if (isCSPHeader(header)) {
header.value = `default-src * 'unsafe-inline' 'unsafe-eval' data: blob:; `;
};
if (isXFrameEnabled(header)) {
header.name = 'foo';
};
if (isCached(header)) {
header.name = 'foo';
};
});
return {
responseHeaders: response.responseHeaders,
};
}, {
urls: ['<all_urls>']
}, ['blocking', 'responseHeaders', 'extraHeaders']);
This logic effectively neutralizes Content-Security-Policy (frame-ancestors) and X-Frame-Options headers by overwriting or renaming them, thus allowing the target page to be embedded in an iframe. Window Mode serves as the fallback for when these header modifications are insufficient or when JavaScript-based frame-busting is used.
Sources: scripts/background.js:33-49, scripts/utils.js:108-115
Summary
The Iframe and Window modes provide a flexible two-pronged approach to active prototype pollution scanning. Iframe Mode is the default, high-volume method that relies on header modification to work across many sites. Window Mode is a crucial alternative, specifically designed to circumvent JavaScript-based frame-busting, ensuring that the scanner can operate even on more restrictive web applications. The choice is managed by a simple buster flag, allowing the core testing logic in exp.js to branch and execute the appropriate strategy.
Sources: README.md, scripts/exp.js:71-108