Stored XSS Explained: The Bug That Attacks Every Visitor


In an earlier post we covered reflected XSS, where a malicious script bounces off a website to a single victim. Stored XSS is its bigger, nastier sibling: the attacker’s script gets saved on the website itself — in a comment, a profile field, a forum post — and then executes in the browser of every single person who views that page.

How Stored XSS Works

  • An attacker finds an input a website stores and later displays without proper escaping — a comment box, a username field, a support ticket.
  • They submit a payload like a harmless proof-of-concept alert (in a real test, a harmless proof-of-concept — never a credential stealer).
  • The website saves it to its database.
  • Every visitor who loads that page runs the script in their browser.

One injection, unlimited victims. That persistence is why stored XSS regularly earns higher bug bounty payouts than reflected XSS — and why it’s treated more seriously by security teams.

Where to Look (On Legal Targets Only)

Only test sites you own, a lab like PortSwigger Web Security Academy, or a bug bounty program whose scope explicitly includes the feature. Good places to probe:

  • Comment sections and forum posts
  • User profile fields (bio, display name)
  • Product reviews
  • Support tickets and contact forms that staff later view
  • File upload filenames that get displayed back

Always use a harmless proof-of-concept payload — never attempt to steal real users’ session tokens, even on a test account. The goal is proof, not harm.

Why Developers Keep Making This Mistake

The root cause is always the same: user input is treated as code instead of data. When a website inserts raw user input into HTML without encoding it, the browser can’t tell the difference between the site’s own script and the attacker’s.

How to Fix It

  • Output encoding is the primary fix. Encode user data when rendering it in HTML so script tags become harmless text instead of executable code. Modern frameworks (React, Angular, Django templates) do this by default — bugs appear when developers bypass it with “raw HTML” features.
  • Validate input on the server, not just the browser. Client-side checks are trivially bypassed.
  • Use Content Security Policy (CSP) as defense in depth: a strict CSP can block inline scripts even if an injection slips through.
  • Set cookies with HttpOnly. This doesn’t prevent XSS, but it stops stolen scripts from reading session cookies — limiting the damage.

The Bug Bounty Angle

When you report stored XSS, your report should include:

  • The exact input field and payload used (harmless PoC only)
  • Steps to reproduce, including where the payload executes
  • A screenshot or short video of the alert firing
  • The impact: who would be affected (all visitors? admins?) and what an attacker could do
  • A suggested fix (output encoding + CSP)

A stored XSS report that shows admin impact — for example, a payload executing when a staff member views a support ticket — is typically worth more than one affecting regular visitors, because admin sessions carry more privilege.

Your Practice Path

Start with PortSwigger’s stored XSS labs (free, legal, designed for learning), then try the same techniques on a local OWASP Juice Shop instance. Only move to live bug bounty targets when you can reliably explain the bug, its impact, and its fix.

Reflected XSS is a trick. Stored XSS is a trap left in the open for everyone to walk into. Learn to find it in labs, report it properly, and you’ll be fixing real websites — and earning real bounties — faster than you think.

Comments

Popular Posts