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
What does the Secure attribute on a session cookie do?
- Hides the cookie from JavaScript
- Sends the cookie only over HTTPS
- Stops cross-site requests carrying the cookie
- 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.
Which findings are genuine session handling weaknesses?
- Session IDs that increase by one per login
- The session ID appears in the URL query string
- Logout only deletes the cookie; the server session stays valid
- The session cookie carries the HttpOnly flag
- 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: 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.
