Bitzu

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

Single choice

Which XSS type stores the malicious script on the server so every visitor to the page runs it?

  1. Reflected XSS
  2. Stored XSS
  3. DOM-based XSS
  4. 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.

Select all that apply

Which measures help prevent XSS?

  1. Context-aware output encoding
  2. A restrictive Content Security Policy
  3. Client-side validation only
  4. Removing the HttpOnly flag from cookies
  5. 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

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.

Download on the App StoreGet it on Google Play

More 312-50 topics in this module