Content scripts run in isolated worlds
Why it matters
CWE-79 (XSS) and CWE-653 (Insufficient Compartmentalization) both apply when content scripts run in the MAIN world. A content script in the MAIN world shares the JavaScript heap with the host page — the page's JavaScript can read and modify the extension's variables, and vice versa. A compromised or malicious page can tamper with the extension's logic directly, override its functions, or read any data it has loaded. OWASP A03 (Injection) governs this. Chrome's ISOLATED world is the default for a reason: it creates a separate JavaScript environment, preventing the host page from accessing or polluting the extension's execution context. The Chrome content script documentation makes this the required default.
Severity rationale
High because running in the MAIN world removes the JavaScript heap boundary between the extension and the host page, allowing the page to directly manipulate extension state and bypass isolation.
Remediation
Remove any world: "MAIN" declarations from your content_scripts entries in manifest.json. Omitting the world property defaults to ISOLATED, which is correct.
{
"content_scripts": [{
"matches": ["https://example.com/*"],
"js": ["content.js"]
}]
}
If you need to expose a function to the page's JavaScript, use window.postMessage from the isolated content script — the page sends a message, the content script receives and validates it, then responds.
DetectionPro
The detection method for this pattern is part of AuditBuffet Pro.
The full method (what to look for, pass and fail conditions, and how results get reported) ships inside the Extension Permissions & Security Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
External references
- cwe · CWE-79 — Improper Neutralization of Input During Web Page Generation (XSS)
- cwe · CWE-653 — Insufficient Compartmentalization
- owasp:2021 · A03
- external · chrome-content-script-worlds — Chrome Extensions: Content Script Execution Environment
Taxons
History
- 2026-04-18·v1.0.0·Initial import from extension-permissions-security·automated