Course contentsShow
← Security
Lesson 631 of 3,05214. Web Security - XSS and Content InjectionFree lesson

Stored XSS: Persistent Attacks

Understanding stored XSS where malicious scripts are saved server-side and executed for all users.

Stored XSS: Persistent Attacks

What you'll learn: How malicious scripts can be saved on a server and automatically attack every user who views them.


The Core Idea

Unlike Reflected XSS (where the attack happens immediately and affects only one victim), Stored XSS (also called Persistent XSS) occurs when an attacker's malicious script gets saved into a web application's database, file system, or other storage. Every time another user views that stored content, the script executes in their browser — no special link required.

Think of it like poisoning a public water fountain: the poison stays there, affecting everyone who drinks from it, rather than only poisoning one person's cup.


How It Works

  1. Attacker submits malicious input — For example, posting a comment like:

    <script>alert('XSS')</script>
    
  2. Server stores it without sanitization — The application saves this directly to the database.

  3. Victims view the page — When anyone loads the comment section, the server retrieves and displays the stored content.

  4. Script executes in every victim's browser — The browser interprets the <script> tag and runs the attacker's code.


Why It's More Dangerous

  • Persistent: Attacks remain active until the malicious data is removed.
  • Wider impact: Affects all users who view the compromised content, not just one target.
  • Stealth: Victims simply browse normally; no suspicious URL is involved.

Common targets: comment sections, user profiles, message boards, product reviews — anywhere user input is stored and displayed to others.


Key Takeaway:
Stored XSS embeds malicious scripts server-side, turning legitimate pages into persistent attack vectors that automatically exploit every visitor.