What is Cross-Site Scripting (XSS)?
You'll learn: How attackers exploit trusted websites by injecting malicious scripts that execute in victims' browsers.
The Core Vulnerability
Cross-Site Scripting (XSS) is a web security flaw where an attacker injects malicious JavaScript (or other client-side code) into a legitimate website. When unsuspecting users visit that page, their browsers execute the attacker's code—thinking it's part of the trusted site.
Think of it like a ventriloquist act gone wrong: the attacker makes the trusted website "speak" malicious commands to the user's browser, and the browser obeys because it trusts the website's origin.
How XSS Works
The attack typically follows this pattern:
- Injection: The attacker finds a way to insert malicious script into the website (through a comment form, URL parameter, profile field, etc.)
- Storage or Reflection: The script either gets stored in the website's database or reflected back immediately in a response
- Execution: When a victim views the compromised page, their browser executes the injected script
- Exploitation: The script can steal cookies (including session tokens), redirect users to phishing sites, or modify page content
Why It's Dangerous
Since the malicious code runs in the victim's browser under the website's domain, it has access to:
- Session cookies and authentication tokens
- Sensitive page content
- The ability to perform actions as the logged-in user
This bypasses the same-origin policy that normally protects users from cross-domain attacks.
Key Takeaway: XSS turns a trusted website into an unwitting accomplice, executing attacker-controlled scripts in users' browsers with full access to that site's privileges and data.