312-50 ยท Web servers and web applications
XSS, CSRF and client-side attacks
Reflected, stored and DOM XSS, CSRF, clickjacking, open redirects, CSP, output encoding and anti-CSRF tokens.
Key points
- XSS: a victim's browser runs attacker script.
- Types: reflected (crafted link), stored (saved on the server), DOM-based (client-side code writes unsafe data).
- CSRF: a logged-in browser sends an unwanted state-changing request.
- Clickjacking: real page under a decoy. Open redirect: bounces users to arbitrary sites.
- Defenses: output encoding, Content Security Policy, anti-CSRF tokens, SameSite cookies, frame-ancestors/X-Frame-Options.
Practice questions
Which XSS type stores the malicious script on the server so every visitor to the page runs it?
- Reflected XSS
- Stored XSS
- DOM-based XSS
- CSRF
Show answer
Answer: B. Stored XSS
Stored XSS persists, for example in a comment. Reflected XSS lives in a single request and DOM XSS is created in client-side code.
Which measures help prevent XSS?
- Context-aware output encoding
- A restrictive Content Security Policy
- Client-side validation only
- Removing the HttpOnly flag from cookies
- Allowing inline scripts from any source
Show answer
Answer: A. Context-aware output encoding, B. A restrictive Content Security Policy
Context-aware output encoding and a restrictive Content Security Policy limit script injection. Client-side-only validation and disabling HttpOnly do not.
True or false: a site that uses HTTPS everywhere is therefore protected from XSS.
Show answer
Answer: False
False. HTTPS protects traffic in transit; XSS is about unsafe handling of data in the page, which HTTPS does not change.
Practice 8 questions on this topic in Bitzu
Short lessons, instant explanations and spaced review of what you get wrong. Free on iOS and Android.
