Application security XSS types 4 min read

Stored XSS vs reflected XSS

A search page shows “You searched for:” followed by your search, inserted as HTML. If someone searches for a script, who does it run for?

  1. Stored: saved once, runs for everyone

    Stored XSS is saved on the server: a forum post, a product review, a display name shown next to every comment. Each time the page is shown, the script goes with it.

    It needs no link and no lure. It runs for every visitor, which is why it’s usually treated as the more serious kind.

    An attacker posts a review containing a script. The site saves it, then serves it inside the page to every visitor, whose browsers run it.

    One post, every reader.

    In short Stored XSS reaches everyone who views the page.

  2. Reflected: bounced back to one person

    The search page doesn’t save anything. The text comes in with the request and goes straight back into the response, so the script only runs for whoever sends that exact request.

    That’s reflected XSS. The attacker has to get someone to open a crafted link, like /search?q=<script>…, one victim at a time.

    An attacker sends someone a crafted search link. When they open it, the request carries the script to the site, which echoes it back into the results page, where it runs for that one person.

    Nothing is saved. Each victim has to open the link.

    In short Reflected XSS needs someone to open a crafted link.

  3. DOM-based: the server never sees it

    A third kind happens entirely in the browser. Page JavaScript reads something from the address, like location.hash or ?name=, and inserts it with innerHTML.

    The server never sees the dangerous text, so server-side checks miss it.

    Two paths. Stored: a saved comment on the server reaches every visitor. Reflected: a crafted link sends text to the server, which echoes it back to the one person who opened the link. storedsaved postevery visitorreflectedcrafted linkone personsame fix for both: encode output
    Stored reaches everyone who looks. Reflected reaches whoever opens the link.

    In short DOM-based XSS lives in the page’s own scripts.

What the kind doesn’t change

Where the text comes from differs; how it runs doesn’t. All three end with untrusted text inserted as HTML.

So one fix covers them all: encode untrusted text wherever it lands in the page, and avoid innerHTML-style shortcuts. Fixing a reflected bug last month doesn’t need a new approach for a stored one.

Keep this

Different sources, same fix: encode untrusted text wherever it lands in the page.

Stored XSS reaches everyone who views the page. Reflected XSS needs someone to open a crafted link. Neither needs a different fix.
Stored
Saved on the server, shown to every viewer.
Reflected
Echoed back from the request, reaches whoever opens the link.
DOM-based
Page scripts insert data from the URL.
Fix
Encode output, everywhere.

Questions worth carrying

Which is hardest to find?

DOM-based XSS, because it can happen without the server ever seeing the text. Code review and browser-based testing find it.

Does a Content Security Policy stop all three?

A strict policy blocks many attacks of every type, but it’s a safety net. Encoding is still the fix.

Sources

Last reviewed 17 November 2026.

Back to · Common attacks What is XSS?