NETLEARN
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
Victim's browserholds the cookie
Siteweb application
Attackermalicious site
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.