How to fix: DOM XSS Sink or Executable javascript: URI
An inline `<script>` writes a URL-derived value (location, document.URL, document.referrer, or window.name) straight into document.write or innerHTML, or a `javascript:` URI in an href or form target carries a payload that reads cookies or URL data.
Why it matters
A value taken from the URL and written into the page without encoding is executed as markup, so anyone who can get a victim to open a crafted link runs script in that victim's session: reading cookies, calling the site's own API as the logged-in user, or rewriting what the page shows. Because the source is the fragment or the referrer, the payload need never reach the server, which is why this class of XSS survives server-side input filtering and does not appear in access logs.
This is a static read of the delivered HTML. It looks for the two shapes that are dangerous regardless of what the server does: a URL-derived source flowing into a page-rendering sink inside a hand-written inline script, and a javascript: URI whose body touches document.cookie, eval, or URL data. A placeholder href such as javascript:void(0) is not reported, and neither is a bundled script, where a router assigning from location is ordinary framework behaviour.
How to fix it
- 1Replace innerHTML and document.write with textContent, or sanitize with a library like DOMPurify before inserting HTML
- 2Never pass location.hash, location.search, document.referrer, or window.name into a sink without encoding them first
- 3Replace an executable javascript: URI with a real event listener bound in a script file
- 4Add a Content-Security-Policy without 'unsafe-inline', which turns a successful injection into a blocked one
Code examples
Read from the URL without creating a sink
// Unsafe: the fragment is parsed as HTML.
el.innerHTML = location.hash.slice(1);
// Safe: the same value, inserted as text.
el.textContent = decodeURIComponent(location.hash.slice(1));
// Safe when markup really is required:
el.innerHTML = DOMPurify.sanitize(decodeURIComponent(location.hash.slice(1)));References
Detected automatically by VulnRadar. The check id is reflected-input, 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 Sink or Executable javascript: URI?
- 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 reflected-input, which stays the same between runs so you can filter, diff, or gate CI on it.
- Which standards does DOM XSS Sink or Executable javascript: URI 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.