Skip to main content
TagManifest /Docs Dashboard

innerHTML assignment detected

Tags assign to innerHTML, which can execute embedded scripts if the content includes user-controlled data. Use textContent or DOM methods instead.

On this page 6

Summary

  • rule_id — innerhtml-usage
  • purpose — Detect Custom HTML tags that assign to .innerHTML, a pattern that can introduce XSS when content includes user-controlled data
  • effect — Flags all matching tags for human review; rule cannot distinguish static from dynamic assignments
  • layer — container
  • reversibility — non-destructive

What fires this

The rule calls getHtmlTags() and filters for tags where codeAnalysis.hasInnerHTML is true. The parser sets that flag when it finds a .innerHTML = assignment in the tag code. Every matching active tag is flagged — the rule does not distinguish static string assignments from user-controlled interpolation. Manual triage is required when this rule fires. Paused tags are excluded.

Why it matters

innerHTML assignment triggers a full HTML parse of the assigned string and executes any <script> tags or event-handler attributes it contains. When the assigned content includes user-controlled data — URL parameters, cookie values, or dataLayer fields sourced from user input — the assignment becomes a cross-site scripting (XSS) vector. Static assignments are lower risk but create a pattern that future developers may extend with dynamic content without recognizing the implication. textContent is the correct replacement for text; createElement and appendChild are correct for structured HTML.

Before / after

// Tag injects a banner message from a URL param
const msg = new URLSearchParams(location.search).get('msg')
document.querySelector('#banner').innerHTML = msg  // XSS vector
// Safe: textContent for text, no script execution possible
const msg = new URLSearchParams(location.search).get('msg')
document.querySelector('#banner').textContent = msg

Remediation

  1. Open each flagged tag and locate the .innerHTML = assignment.
  2. Identify what value is being assigned — a static string, a variable, or an expression.
  3. If the value is a static string with no runtime components, replace with textContent or a DOM-construction approach.
  4. If the value includes any variable that could originate from URL parameters, cookies, or user input, treat this as an active XSS risk and prioritize replacement.
  5. For text content, use el.textContent = value.
  6. For HTML structure, use createElement and appendChild rather than a string template.
  7. If the assignment comes from a vendor snippet you cannot modify, document the risk and confirm the snippet source is always static.

Metadata

Severity
low
Tier
optimization
Category
security
Layer
container
Version
1
Effort
2hr (about 2 hours)
Reversibility
non-destructive

See also

Examples

Evaluate
curl https://developer.tagmanifest.com/v1/evaluate-rule \
  -H "Authorization: Bearer $TM_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"rule_id":"innerhtml-usage","url":"https://example.com"}'