Skip to main content

Unsafe HTML assignment

Detects innerHTML, outerHTML, and insertAdjacentHTML receiving non-literal values.

DetailValue
Check IDUNSAFE_INNERHTML
SeverityHigh
How it runsDeterministic scan and agent review
Applies toApps with a theme app extension

extensions/product-badge/assets/badge.js

const params = new URLSearchParams(window.location.search);

// Any non-literal value assigned to innerHTML, outerHTML, or
// insertAdjacentHTML is a script-execution sink. eval() and new
// Function() are flagged the same way.
document.querySelector(".badge").innerHTML = params.get("label");

Use textContent where possible or sanitize with DOMPurify before rendering.

For more detail, see Cross-site scripting.

extensions/product-badge/assets/badge.js

const params = new URLSearchParams(window.location.search);

// textContent renders the value as text, so markup in it stays
// inert. When you genuinely need HTML, sanitize with DOMPurify
// first.
document.querySelector(".badge").textContent = params.get("label");


Was this page helpful?