How to fix: DOM XSS sinks with user-controlled input
User-controlled data is assigned to XSS-prone DOM sinks such as innerHTML, document.write, or eval without sanitization.
Why it matters
DOM-based XSS allows attackers to inject and execute arbitrary JavaScript in the victim's browser, stealing session cookies, redirecting the user, making authenticated API requests on their behalf, or completely taking over their session.
DOM XSS occurs when user-controlled data flows into dangerous browser APIs without sanitization. Use safe DOM APIs and sanitize when HTML is required.
How to fix it
- 1Replace innerHTML/outerHTML with textContent for plain text
- 2Use DOMPurify.sanitize() when HTML rendering is required
- 3Implement a Content Security Policy to limit script execution
Code examples
Use textContent instead of innerHTML
// Unsafe: innerHTML with user-controlled data
element.innerHTML = userInput;
// Safe: use textContent for plain text
element.textContent = userInput;
// Or use DOMPurify for HTML content
import DOMPurify from 'dompurify';
element.innerHTML = DOMPurify.sanitize(userInput);References
Detected automatically by VulnRadar. The check id is dom-xss-sinks, 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 DOM XSS sinks with user-controlled input?
- 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 dom-xss-sinks, which stays the same between runs so you can filter, diff, or gate CI on it.
- Which standards does DOM XSS sinks with user-controlled input 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.