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
- 1HTML-encode all user-controlled values before inserting into HTML context
- 2Use a templating engine that auto-escapes by default
- 3Implement Content Security Policy to limit script execution
Code examples
Escape user input before rendering
// Unsafe: user input rendered as HTML
div.innerHTML = req.query.name;
// Safe: escape before inserting
function escapeHtml(s) {
return s.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>');
}
div.textContent = req.query.name; // or use textContentReferences
Detected automatically by VulnRadar. The check id is html-injection-patterns, stable across every scan so you can filter or diff on it.
More content checks
- MediumPotential Open Redirect Parameters
- HighDirectory Listing Appears Enabled
- MediumSensitive File References Detected
- HighPotentially Outdated JavaScript Libraries
- Inforobots.txt Present - Review Manually
- InfoCMS / Technology Fingerprinting
- MediumPotentially Dangerous Inline JavaScript
- LowServer version disclosed in response header
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.