Bitzu

312-50 ยท Session hijacking

Session hijacking countermeasures

HTTPS and HSTS, Secure/HttpOnly/SameSite cookie flags, token regeneration, short timeouts, IPsec, and detection tools.

Key points

  • HTTPS everywhere, pinned with HSTS.
  • Cookie flags: Secure (HTTPS only), HttpOnly (hidden from JavaScript), SameSite (limits cross-site sending).
  • New session ID at login and privilege change; long random IDs.
  • Invalidate on the server at logout; idle and absolute timeouts.
  • Network: IPsec or VPNs; watch ARP anomalies with IDS or ARP monitoring.

Source: https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/Cookies

Practice questions

Single choice

What does the HttpOnly cookie attribute prevent?

  1. Sending the cookie over plain HTTP
  2. Reading the cookie from JavaScript
  3. Sending the cookie on cross-site requests
  4. Caching the cookie on the server
Show answer

Answer: B. Reading the cookie from JavaScript

HttpOnly hides the cookie from document.cookie, limiting theft through XSS. It does not encrypt transport (that is Secure/HTTPS) or stop CSRF (that is SameSite).

Select all that apply

Which measures reduce the risk of session hijacking?

  1. Regenerate the session ID after authentication
  2. Include the session ID in URLs for convenience
  3. Apply short idle timeouts
  4. Set SameSite on session cookies
  5. Reuse one ID for a user across all logins
Show answer

Answer: A. Regenerate the session ID after authentication, C. Apply short idle timeouts, D. Set SameSite on session cookies

New IDs at login stop fixation, short idle timeouts shrink the window, and SameSite limits cross-site use. Putting IDs in URLs or reusing one ID forever does the opposite.

True or false

True or false: setting the Secure attribute on a cookie also stops JavaScript from reading it.

Show answer

Answer: False

False. Secure only restricts the cookie to HTTPS requests. Hiding it from JavaScript is the job of HttpOnly.

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