Bitzu

CPSA ยท Web application assessment: injection, sessions and code

Session handling pitfalls

Predictable IDs, fixation, missing expiry, cookie flags and session ID exposure.

Key points

  • A session ID is a temporary password.
  • Predictable or short IDs can be guessed; need 64+ bits of entropy from a secure random source.
  • Fixation: pre-login ID kept after login; renew the ID at login and on privilege change.
  • Expiry: server-side idle and absolute timeouts; destroy the session at logout.
  • Cookie flags: Secure (HTTPS only), HttpOnly (hidden from script), SameSite.
  • IDs in URLs leak via logs, history, Referer.

Source: https://cheatsheetseries.owasp.org/cheatsheets/Session_Management_Cheat_Sheet.html

Practice questions

Single choice

What does the Secure attribute on a session cookie do?

  1. Hides the cookie from JavaScript
  2. Sends the cookie only over HTTPS
  3. Stops cross-site requests carrying the cookie
  4. Encrypts the cookie value on the client
Show answer

Answer: B. Sends the cookie only over HTTPS

Secure makes the browser send the cookie only over HTTPS. Blocking script access is HttpOnly, and restricting cross-site sending is SameSite.

Select all that apply

Which findings are genuine session handling weaknesses?

  1. Session IDs that increase by one per login
  2. The session ID appears in the URL query string
  3. Logout only deletes the cookie; the server session stays valid
  4. The session cookie carries the HttpOnly flag
  5. The ID is 128 bits from a secure random generator
Show answer

Answer: A. Session IDs that increase by one per login, B. The session ID appears in the URL query string, C. Logout only deletes the cookie; the server session stays valid

Sequential IDs are guessable, IDs in URLs leak through logs and Referer, and a logout that does not destroy the server-side session leaves the ID valid. A long random ID and HttpOnly are good practice, not flaws.

True or false

True or false: putting the session ID in the URL is acceptable as long as the site uses HTTPS.

Show answer

Answer: False

False. HTTPS protects the wire, but URLs still end up in server and proxy logs, browser history, bookmarks and Referer headers, and they make fixation easier.

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 CPSA topics in this module