Page data is sanitized
Why it matters
CWE-79 (XSS) in a content script context is dangerous not just for the extension user but for the host page: a content script that reads text from the DOM and inserts it back via innerHTML without sanitization can be triggered by the host page itself injecting a payload. CWE-116 (Improper Encoding or Escaping) names the adjacent failure. OWASP A03 (Injection) applies. Content scripts occupy a trusted position relative to the host page — they can read storage, message the background script, and interact with chrome.* APIs — so an XSS here has a blast radius beyond what a typical page-level XSS would achieve.
Severity rationale
High because unsanitized `innerHTML` in a content script creates an XSS vector in a trusted extension context that can access `chrome.*` APIs and user storage, extending the blast radius beyond the page.
Remediation
Replace innerHTML assignments with textContent for text data. If rendering HTML from page data is unavoidable, wrap it with DOMPurify before insertion.
// src/content.js — safe DOM manipulation
element.textContent = scrapedText; // Safe: no HTML parsing
// If HTML is required:
import DOMPurify from 'dompurify';
element.innerHTML = DOMPurify.sanitize(scrapedHtml);
Never pass a variable derived from document.querySelector, location.href, or window.name directly into innerHTML or outerHTML.
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-116 — Improper Encoding or Escaping of Output
- owasp:2021 · A03
Taxons
History
- 2026-04-18·v1.0.0·Initial import from extension-permissions-security·automated