Session Management (SM5)

SESSION MANAGEMENT
5

O John pode prever ou adivinhar identificadores de sessão porque não são alterados quando o papel do utilizador muda (por exemplo, antes e depois da autenticação) e ao alternar entre comunicações não encriptadas e encriptadas; ou porque não são suficientemente longos e aleatórios; ou porque não são alterados periodicamente.

How to play?

Static, predictable, and insufficiently random session identifiers that aren’t rotated during role or communication changes enable attackers to hijack user sessions and spoof identities. See Session Management 7 (SM7) for session termination on logging out.

Scenario: John’s Prediction of Session Identifiers

Imagine a scenario where John exploits weaknesses in session management by predicting or guessing session identifiers. He capitalizes on several system vulnerabilities:

  1. Static Identifiers Across Role Changes: Session IDs remain unchanged when a user’s role alters, such as pre and post-authentication.
  2. Unchanged IDs Across Communication Modes: Identifiers do not change when switching between non-encrypted and encrypted communications.
  3. Insufficient Length and Randomness: Session identifiers are not sufficiently long or randomly generated.
  4. Lack of Periodic ID Refresh: The system does not periodically change session identifiers.

Example

John targets a website where users’ session IDs remain the same before and after they log in. By predicting the session ID pattern used when users are browsing without logging in, John guesses the IDs post-login. This allows him to hijack sessions where users are authenticated and potentially access sensitive information or make unauthorized purchases.

Threat Modeling

STRIDE

This scenario maps primarily to STRIDE: Spoofing.

Spoofing involves impersonating a legitimate user. John predicts or guesses session identifiers because the system does not rotate or randomize them appropriately. By hijacking a valid session ID, he assumes the identity of the authenticated user, which is classic Spoofing.

What can go wrong?

Such practices expose users to session hijacking and potential privacy breaches, as attackers can easily predict or guess session IDs.

For more things that can go wrong, see the Common Attack Patterns related to this card in the table below.

What are we going to do about it?

  1. Implement a system to regenerate session IDs upon any change in user state, especially during authentication processes and periodically otherwise.
  2. Ensure session IDs are sufficiently long, complex, and randomly generated.
  3. Regularly refresh session identifiers to prevent them from being guessed or reused over time.
  4. Employ strict security measures for session management across both encrypted and non-encrypted communications.

For detailed advice on how to mitigate threats related to the card, see the ASVS and OWASP Developer Guide requirements in the table below.

Mappings

OWASP ASVS (v4.0): 3.2.1,3.2.2,3.2.4,3.3.1

OWASP DevGuide: SM2,SM3,SM5,SM8,SM9,SM10,SM11,SM12,SM13,SM14,SM15

STRIDE: Spoofing

OWASP SCP: 60,62,66,67,71,72

OWASP AppSensor: SE4,SE5,SE6

CAPEC™: 31,59,464

SAFECode™: 28

ASVS (4.0.3) Cheat Sheet Series Index

Session Fixation

Session Hijacking (Man-in-the-Middle)

OWASP Cornucopia

OWASP Cornucopia is a mechanism in the form of a card game to assist software development teams identify security requirements in Agile, conventional and formal development processes. It is language, platform and technology-agnostic, and is free to use. OWASP Cornucopia is licensed under the Creative Commons Attribution-ShareAlike 4.0 license, so you can copy, distribute and transmit the work, and you can adapt it, and use it commercially, but all provided that you attribute the work and if you alter, transform, or build upon this work, you may distribute the resulting work only under the same or similar licence to this one.

© 2012-2025 OWASP Foundation. The Open Worldwide Application Security Project (OWASP) is a nonprofit foundation that works to improve the security of software.