DOM-Based XSS Explained: Examples & Prevention | Vooki Pro

DOM-based XSS (DOM XSS) explained

DOM-based cross-site scripting (DOM XSS) is a type of XSS where the vulnerability is in the page's own client-side JavaScript. The script reads data from a source the attacker can control, such as the URL, and writes it into the page in an unsafe way.

Every HTML document has a Document Object Model (DOM): the browser's object representation of the page. In DOM XSS, the malicious data never has to appear in the server's response. The page's script modifies the DOM using attacker-controlled data, and the browser runs it.

See it in action

The video below demonstrates DOM XSS using the Damn Vulnerable Web Application (DVWA), a deliberately vulnerable application for practice.

How to defend against DOM-based XSS

  • Avoid writing data from untrusted sources into the HTML document. Where you must, use safe methods such as textContent or setAttribute instead of innerHTML or document.write.
  • Do not pass untrusted data to eval, setTimeout with a string, or similar functions.
  • If untrusted data must be inserted, encode it for the exact context (HTML, JavaScript or URL). This is easy to get wrong, so prefer the safe methods above.
  • Validate input against an allow-list where possible, for example letters, digits and spaces only.
  • Add a strict Content Security Policy as a second layer of defence.

How Vooki Pro helps

  • Includes checks for DOM-based XSS.
  • Flags unsafe JavaScript sinks such as innerHTML, eval and string-based setTimeout.
  • Enabling AI detection in the scan wizard also enables DOM-XSS detection.
  • Also checks client-side prototype pollution and unsafe postMessage handling.

Frequently asked questions

How is DOM XSS different from reflected XSS?

In DOM XSS the vulnerable code runs in the browser: the page's own JavaScript writes untrusted data into the page, often without the server ever seeing the payload.

How do I prevent DOM XSS?

Use safe sinks such as textContent, avoid innerHTML and eval with untrusted data, and add a strict Content Security Policy.

Try Vooki Pro free for 7 days

Find DOM XSS that server-side testing misses. The trial unlocks every feature for 7 days, and scanning runs on your own machine.

Get Vooki Pro →  ·  How to run a web application scan

Related: Cross-Site Scripting (XSS): reflected, stored and DOM-based · A practical guide to Content Security Policy (CSP)

    • Related Articles

    • Cross-Site Scripting (XSS): reflected, stored and DOM-based

      Cross-site scripting (XSS) lets an attacker run their own JavaScript in another user's browser, inside your website. It is one of the most common web vulnerabilities and appears in the OWASP Top 10 under Injection. There are three main types: ...
    • OWASP Top 10: the most critical web application security risks

      The OWASP Top 10 is an awareness document for web application security, published by the Open Worldwide Application Security Project (OWASP). It represents a broad consensus among security experts about the most critical security risks to web ...
    • Error-based SQL injection

      SQL injection lets an attacker change a database query by supplying crafted input. There are three common techniques: union-based, error-based and blind SQL injection. This article covers the error-based technique. How it works A common first test ...
    • Network vulnerability scanning explained

      Vulnerability scanning is an automated inspection of computers, networks and applications to identify security weaknesses that an attacker could exploit. What a network vulnerability scan does A network vulnerability scanner checks systems and ...
    • The OWASP API Security Top 10, explained

      The OWASP API Security Top 10 lists the most critical risks specific to APIs. It differs from the classic OWASP Top 10 because APIs fail in their own ways, especially around authorization and data exposure. How it works The list covers broken ...