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.
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
- Open each flagged tag and locate the
.innerHTML =assignment. - Identify what value is being assigned — a static string, a variable, or an expression.
- If the value is a static string with no runtime components, replace with
textContentor a DOM-construction approach. - 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.
- For text content, use
el.textContent = value. - For HTML structure, use
createElementandappendChildrather than a string template. - 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
- Security rules — other rules in this category
- Health score — how this rule contributes to the score
- Rules catalog — browse all rules
Examples
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"}'
User: Run innerhtml-usage on https://example.com
# Tool call
{
"tool": "evaluate_rule",
"arguments": {
"rule_id": "innerhtml-usage",
"url": "https://example.com"
}
}