Skip to main content
HighContentOWASP A03:2021CWE-79

How to fix: HTML injection pattern detected

User-controlled input appears to be reflected in the HTML response without proper encoding, enabling HTML injection.

Why it matters

HTML injection allows attackers to insert arbitrary HTML content into the page: creating fake login forms (phishing), modifying page appearance, injecting links, or redirecting users, and may escalate to XSS if script tags can be injected.

All user-controlled values that appear in HTML output must be HTML-encoded to prevent injection.

How to fix it

  1. 1HTML-encode all user-controlled values before inserting into HTML context
  2. 2Use a templating engine that auto-escapes by default
  3. 3Implement Content Security Policy to limit script execution

Code examples

Escape user input before rendering

JavaScript
// Unsafe: user input rendered as HTML
div.innerHTML = req.query.name;

// Safe: escape before inserting
function escapeHtml(s) {
  return s.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
}
div.textContent = req.query.name; // or use textContent

References

Detected automatically by VulnRadar. The check id is html-injection-patterns, stable across every scan so you can filter or diff on it.

See every content check

Questions

How severe is HTML injection pattern detected?
VulnRadar rates this high severity in the content category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
Does VulnRadar check for this automatically?
Yes. It runs as part of every scan under the check id html-injection-patterns, which stays the same between runs so you can filter, diff, or gate CI on it.
Which standards does HTML injection pattern detected map to?
It maps to CWE-79. In the OWASP Top 10 it falls under A03:2021.

Missing a check?

The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.

Propose a checkHow a check is built

Scan your own site for html injection pattern detected

VulnRadar runs this check and hundreds more against a URL in seconds. No agent to install, just paste a URL.

Or scan this site as a demoRead the docs

How to fix: HTML injection pattern detected | VulnRadar