Skip to content

Lesson 2 of 9 · 22m

Reflected, Stored, and DOM XSS

The three delivery classes differ in reach, persistence, and detection — but the execution primitive is the same browser parser failure.

Reflected, stored, and DOM XSS are categories of delivery, not categories of JavaScript. The distinction matters because it tells you who is exposed, how persistent the attack is, where logs will appear, and which fixes are realistic.

Reflected XSS: the request is the weapon

Reflected XSS happens when a request parameter is immediately copied into the response:

<!-- Rails-era pattern, still seen in legacy apps -->
<p>Hello <%= params[:name] %></p>

The victim must usually click a malicious URL. Attackers hide these behind shortened links, redirects, URL-encoded parameters, and believable phishing pages. Impact depends on the victim's session and what client-side code can reach: cookies without HttpOnly, sensitive DOM data, privileged actions, internal apps.

Stored XSS: the application distributes it for you

Stored XSS is saved in a database or file and served later:

comment.body = '<img src=x onerror="fetch(`/api/admin/users`).then(r=>r.text()).then(exfil)">'

The blast radius is larger because one payload can hit every viewer. The nastiest stored bugs land in places operators trust: admin dashboards, support tooling, log viewers, moderation queues. A payload in a low-value public page becomes high-value when an employee reviews it inside an internal console.

DOM XSS: the server never sees the payload

DOM XSS happens entirely in JavaScript:

const hash = location.hash.slice(1);
document.getElementById("welcome").innerHTML = "Welcome " + hash;

Attack URL:

https://app.internal/welcome#<img src=x onerror=alert(1)>

Fragments are not sent to the server, so WAF logs and access logs can be empty. This is why greping server templates for <script> misses real bugs. You audit client-side data flow: location, postMessage, localStorage as sources; innerHTML, outerHTML, insertAdjacentHTML, document.write, eval, new Function, and jQuery .html() as sinks.

Field notes

  • Reflected bugs often become stored when input is saved into profiles, tickets, filenames, or error logs.
  • DOM sanitizing after insertion is too late if a mutation or handler already executed.
  • SPA routing does not make reflection safe; it often creates more dangerous client-side sinks.
  • When reporting, state the class, source, sink, victim, and reachable impact — not just alert(1).

Was this lesson helpful?

Sign in to rate