All three XSS types end with attacker JavaScript running in the victim’s browser. What differs is where the malicious input gets processed.
Stored XSS
The most critical variant. The payload is saved to the back-end database (or any persistent store) and served to every visitor who loads the affected page.
- Victim count: any user who visits the page
- Trigger: automatic — payload runs every page load
- Testing: submit payload → refresh → does it still fire?
Classic test payload:
<script>alert(window.origin)</script>window.origin confirms which domain actually executed the code — important when the vulnerable component is rendered in an iframe or shared across subdomains.
If the alert pops after a page refresh, you have Stored XSS. Viewing page source should show your payload embedded in the HTML.
If alert() is blocked (some apps filter it specifically), use:
<plaintext>— stops the browser from rendering any HTML after it, turning the rest of the page into visible textprint()— opens the print dialog, loud confirmation that JS ran
Reflected XSS
The payload is not stored — it’s echoed back inside the HTTP response for the single request that contained it. Classic example: a search box that prints No results for "<your input>" without encoding.
- Victim count: only users who follow a crafted URL
- Trigger: victim clicks a link with the payload in a GET parameter
- Testing: inject payload → check if it appears unescaped in the response
Exploitation usually means crafting a URL like:
http://target/search?q=<script>alert(1)</script>
and getting victims to visit it via phishing, DM, link shortener, etc.
Same test payloads as Stored XSS — difference is only persistence.
DOM-Based XSS
The vulnerability lives entirely in client-side JavaScript. The payload never reaches the server as executable code — it’s processed by JS that reads from a source and writes to a sink without sanitization.
Source → Sink
- Source — where attacker-controlled input enters JS
document.URL,document.location,location.hash,location.search- Input field values, cookies,
postMessagedata
- Sink — where that data gets written into the DOM
innerHTML,outerHTML,document.write(),document.writeln()- jQuery:
.html(),.append(),.after(),.before() eval(),setTimeout(string),setInterval(string)(code-execution sinks)
Example Vulnerable Flow
// Source: URL hash
var task = document.URL.substring(pos + 5, document.URL.length);
// Sink: innerHTML
document.getElementById("todo").innerHTML = "<b>Next Task:</b> " + decodeURIComponent(task);An attacker-supplied value at #task=<payload> ends up in innerHTML with no escaping.
innerHTML Blocks <script> Tags
Modern browsers won’t execute <script> inserted via innerHTML after page load. Workaround: use event-handler attributes on other tags:
<img src="" onerror="alert(window.origin)">
<svg onload="alert(window.origin)">
<body onload="alert(1)">Delivery
http://target/#task=<img src='' onerror=alert(window.origin)>
Fires client-side as soon as the victim loads the URL. The server never sees the payload — meaning server-side WAFs are useless here.
Which Type Should You Test First?
In order of impact:
- Stored — hits every visitor automatically; highest value
- DOM — bypasses server-side defenses; invisible to WAFs
- Reflected — needs social engineering to land, but still common
In order of ease-of-discovery:
- Reflected — single request, instant feedback
- Stored — submit, then revisit the display page
- DOM — requires reading JavaScript source
