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
Caution

Metafields and metaobjects outside your app-owned namespace are lower-trust input, even when your app is the only app that writes them, because other installed apps can overwrite them. HTML or script stored in a shared namespace isn't trusted content. To find these values, see SHARED_NAMESPACE_METAFIELD_RENDER.


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?