System Design
13. Security ArchitectureAnimated
Cross-Site Scripting (XSS)
Attackers run script in other users' browsers.
The idea
Untrusted input shown without escaping can execute as code.
Watch it work
Press play, pause, or step through. Some animations have settings you can change.
- current message
- earlier
- failure or attack
An attacker submits script as a comment.
- step:
- 1/5
- from:
- Attacker
- to:
- Site
1/5
Time runs downward. Solid arrows are requests, dashed arrows are replies.
Step by step
- 1Escape output
- 2Use a Content Security Policy
- 3Sanitise HTML
- 4Set HttpOnly cookies
Where it is used
Web apps.
Watch out for
Escaping must match the context (HTML, attribute, JS).