Session Management (SM9)
Іван може вкрасти ідентифікатори сесій або токени авторизації, оскільки вони надсилаються незахищеними каналами, або записуються в журнали, або розкриваються в повідомленнях про помилки, або включені до URL-адрес, або доступні без потреби з боку коду, кешу або балансувальників навантаження, на які зловмисник може впливати або які може змінювати
Exposed session identifiers—transmitted insecurely, logged, leaked in error messages, included in URLs, or accessible to attacker-controlled code—can be stolen and used to hijack and spoof user sessions.
Scenario: Ivan’s Session Identifier Theft
Picture a scenario where Ivan, a savvy attacker, steals session identifiers or authorization tokens due to their exposure through various insecure means. He exploits system weaknesses such as:
- Transmission over Insecure Channels: Session identifiers or tokens are sent over unencrypted connections.
- Logging of Identifiers: Session IDs or tokens are unnecessarily logged in system or application logs.
- Exposure in Error Messages: Identifiers are revealed in verbose error messages.
- Inclusion in URLs: Session IDs or tokens are included in URLs, making them vulnerable to exposure.
- Accessibility by Attacker-Influenced Code: Session identifiers or tokens are accessible by code or scripts that an attacker can manipulate or alter.
- Accessibility through Cache or Load Balancers: Session identifiers or tokens are stored in caches or load balancers that may not be secure, allowing attackers to access them through cache poisoning or other attacks.
Example
Ivan targets a web application that transmits session identifiers over HTTP instead of secure HTTPS. He intercepts network traffic and captures these identifiers as they are transmitted unencrypted. Additionally, the application includes session IDs in URL parameters, which can be leaked through browser history or referrer headers. Using these stolen session IDs, Ivan hijacks active user sessions, gaining unauthorized access to their accounts and data.
Threat Modeling
STRIDE
This scenario maps primarily to STRIDE: Spoofing.
Spoofing involves impersonating a legitimate user or entity. Ivan steals session identifiers through insecure transmission, logging, URL parameters, or code exposure. By using these stolen session IDs, he hijacks active sessions and impersonates the legitimate user, which is classic Spoofing.
What can go wrong?
Such practices expose users to session hijacking and potential data breaches, as their session identifiers can be easily intercepted and misused.
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?
Protect session identifiers as if they are account credentials. For HTTP cookies:
- Ensure all communication involving session identifiers is encrypted, preferably using HTTPS.
- Avoid logging session IDs or exposing them in error messages.
- Refrain from including session identifiers in URLs, opting for more secure methods of transmission.
- Limit the accessibility of session identifiers in the application’s code, especially to scripts or areas that could be compromised.
- Set the 'Secure' attribute for cookies transmitted over a TLS connection.
- Set cookies with the HttpOnly attribute, unless you specifically require client-side scripts within your application to read or set a cookie's value.
- Set HTTP Strict Transport Security (HSTS) header and add your domain to web browser pre-load lists.
- When using server caches, load balancers, or other intermediaries, ensure that session identifiers are not stored in a way that they can be accessed by unauthorized parties, such as through cache poisoning or other attacks. Consider using secure, encrypted storage for session identifiers in these components.
- Never store tokens in local storage or session storage, as these can be accessed by malicious scripts or browser extensions. Use cookies instead, or use a BFF pattern where the backend handles token storage and management.
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 (v5.0): 3.3.1,3.3.2,3.3.3,3.3.4,3.4.1,3.4.2,3.7.4,10.1.1,10.4.16,12.1.1,12.2.1,12.3.1,12.3.3,14.2.1,14.2.2,16.2.5,16.5.1
OWASP DevGuide: SM11,SM12,SM15,SM16,DP5,SL5,EE6
STRIDE: Spoofing
SAFECode™: 28
CAPEC Map
| Code | Title | ASVS |
|---|---|---|
| 31 | Accessing/Intercepting/Modifying HTTP Cookies | 3.3.1,3.3.2,3.3.3,3.3.4,3.4.1,3.7.4,10.1.1,10.4.16,12.1.1,12.2.1,12.3.1,12.3.3,14.2.1,14.2.2,16.2.5,16.5.1 |
| 37 | Retrieve Embedded Sensitive Data | 10.1.1,10.4.16,14.2.1,14.2.2,16.2.5,16.5.1 |
| 593 | Session Hijacking | 3.3.1,3.3.2,3.3.3,3.3.4,3.4.1,3.7.4,12.1.1,12.2.1,12.3.1,12.3.3,14.2.1,14.2.2,16.2.5,16.5.1 |