Revision as of 13:08, 18 October 2013 by Abbas Naderi (session fixation and elevation covered)
- If the system is critical, Session IDs should be cryptographically secure (i.e non determinable)
- In big systems, sessions should not be stored in files (default PHP behavior). They should be stored in memory or in databases, to prevent DOS attacks on new sessions.
- As soon as a confidential or higher session is formed for a user, they should have all their traffic transmitted through SSL. SessionID is almost as important as passwords.
- A policy should be defined and forced on an application, to define the number of sessions a user can have. (One, Many, etc.) If this is left vague, it usually leads to security flaws.
- Sessions require a general timeout, which happens at a certain time after creation (usually a week), and an idle timeout, which happens after a certain time of the session being idle (usually 30 minutes).
- The idle timeout can be changed depending on the nature of the application (smaller for banking applications, larger for email composing clients)
- The idle timeout doesn't have to be precise. The application can check for it every 2 minutes, and flush all timed-out idle sessions.
- Sessions should be rolled when they are elevated. Rolling means that the session-id should be changed, and the session information should be transferred to the new id.
- Sessions need to be cleared out on logout. It is a good idea to dispose of the session-id on logout as well.
Generally three sorts of session attacks are possible:
- Session Hijacking: stealing someone's session-id, and using it to impersonate that user.
- Session Fixation: setting someone's session-id to a predefined value, and impersonating them using that known value
- Session Elevation: when the importance of a session is changed, but its ID is not.
- Session-ids should be placed inside cookies, and not in URLs. URL informations are stored in browser's history, and HTTP Referrers, and can be accessed by attackers.
- Geographical location checking can help detect simple hijacking scenarios. Advanced hijackers use the same IP (or range) of the victim.
- An active session should be warned when it is accessed from another location.
- An active users should be warned when s/he has an active session somewhere else (if the policy allows multiple sessions for a single user).
- If the application sees a new session-id that is not present in the pool, it should be rejected and a new session-id should be advertised. This is the sole method to prevent fixation.
- All the session-ids should be generated by the application, and then stored in a pool to be checked later for. Application is the sole authority for session generation.
- Whenever a session is elevated (login, logout, certain authorization), it should be rolled.
- Many applications create sessions for visitors as well (and not just authenticated users). They should definitely roll the session on elevation, because the user expects the application to treat them securely after they login.
- When a down-elevation occurs, the session information regarding the higher level should be flushed.