Lesson 02Attack
XSS & CSRF: Two Classic Holes
These two longest-lived web attacks are often confused. XSS injects code into a page you trust; CSRF makes the browser send a request on your behalf. Opposite directions, equally frightening.
- Layer
- Layer 7 · Application (browser)
- Reference
- OWASP Top 10
- Steps
- 7
NETLEARN · your study buddy
Net · guide
Hi! I’m Net, your guide today. We’ll look at XSS & CSRF: Two Classic Holes in the Web Attacks module.
how it works
tap Net · advance one step⟲ button · start overEnter · open the full explanation
legendcautionmessage in flight
Common misunderstandings
- Sanitizing input alone is not enough and is not always needed. What is required is escaping correctly per context (HTML, attribute, URL, JS), not trusting one universal filter.
Key notes
- Different directions
- XSS injects code into a trusted page; CSRF sends a request from a malicious page using your session.
- CSRF token
- A random per-session value that must be included in the form. The attacker cannot guess it.
- SameSite
- A cookie with SameSite=Lax/Strict is not included on cross-site requests, cutting off simple CSRF.
- CSP
- Content-Security-Policy limits which scripts may run, reducing the impact of XSS.
