SCW Icons
hero bg no divider
Blog

Les codeurs conquièrent la sécurité : série Share & Learn - Faiblesses de la gestion des sessions

Jaap Karan Singh
Published Jan 31, 2019
Last updated on Mar 08, 2026

You navigate to a website and log in. As normal, you fill up your cart with products you'd like to buy. Then, whoops - your hand slips and closes the browser tab. After a minor panic, you enter the URL of the site back into the browser and hit the "Enter" key. You are brought back into the site, logged in, and all of your items are still in the cart. Whew.

How did the site know who you were without re-authenticating? It identified you because it was using sessions. Sessions are key to a good user experience when using the web. However, managing sessions incorrectly can lead to security holes that attackers can exploit.

Let's now review what session management means, how weak session management can hurt you, and what you can do to manage sessions properly.

Understanding Session Management Weaknesses

A session refers to a value stored on the server, specific to a single user of the application. This is necessary for two reasons: First, HTTP is a stateless protocol. Each request is separate and has no knowledge of requests that have come before or after it. A session helps the server track who sent the request. Otherwise, you would need to login every time you clicked on a button or a link.

The second reason for sessions is for authorization of the user. The session identifier can be used to recognize a specific user with specific rights within the system. The application will know who the person is and what they are allowed to do.

There are two components to a session. A data store on the server-side stores a session identifier and maps it to information about the user such as their user id or cart information. The same session identifier is sent to the browser in a cookie. The cookies are stored by the browser on the user's system. The client passes the cookie with each request, letting the server knows that this request is coming from the same user. Most applications use sessions to track users both pre- and post-authentication.

Proper session management is essential to the security of an application. A valid session ID has the same level of trust as a username/password, or even a second-factor authentication token.

Why Poor Session Management is Dangerous

Poor session management can lead to complete account takeover. This means customer data can be stolen, or products could be purchased fraudulently. There are several ways for attackers to obtain a valid session ID.

A session fixation attack occurs when sessions are not changed at key times, such as when a user logs into the system, and if session identifiers can be set using the URL. Setting session identifiers in this way may be used to keep users logged in across different applications that use the same authentication source. In this case, an attacker can browse to a website and gain a session ID. The attacker then sends a URL to an unsuspecting victim via email with the session ID in the URL. The victim clicks the URL in the email and logs into the website. If the session ID is not rotated upon login, the attacker now has a valid, authenticated session ID. This allows complete account takeover.

Another attack upon poor session management is a brute-force guessing attack. When developers try to create their own session management systems, often they use session IDs that are pretty simple to guess. These could be a sequence (1, 2, 3) or a predictable pattern of some kind. The attacker simply keeps guessing session IDs until a valid one is discovered. This also leads to an account takeover.

Sessions that aren't invalidated automatically after a certain amount of time has passed can be exploited to attack users. A successful cross-site request forgery attack depends on sessions that are still valid after the user leaves the site. Let's say an attacker places an iframe or image on a site visited by the user. The "src" (source) attribute is set to the URL of the vulnerable site and performs an action on behalf of the user. For example, a vulnerable banking application could be made to transfer money to an attacker's account without the user's permission.

Session management can be tricky, and weaknesses can be devastating. However, it's a well-known problem and it can be solved.

Defeat Insecure Session Management

Session management is a core piece of any web application. As a result, many web development frameworks have built-in session management functionality. These systems have been scrutinized by experts to find and weed out problems. Use them.

Some common properties of good session management include:

     Random session IDs generated that attackers can't guess

     Sessions are invalidated when a user logs out

     Sessions are invalidated automatically after a certain amount of time has passed

     Session IDs are changed after the user logs in

     Session IDs that are at least 128 bits long to prevent brute force attacks

Web frameworks such as Spring, ASP.NET Core, Rails, and Django have these properties and should be used for their higher security standards in this instance.

Bottom line: Don't create your own session management system from scratch.

Once the session IDs are created, they need to be protected. Set the Secure and HttpOnly flags to "true'on session cookies. This ensures that their value cannot be retrieved with JavaScript and the browser will only send the cookie via HTTPS, preventing attackers from stealing someone's session in transit.

Secure Your Sessions

Check out our free learning resources to find out more about secure session management. Learning how to secure your sessions will help prevent user account takeover, reputation damage, and lost revenue due to security breaches. Secure your sessions and keep your users safe.

Afficher la ressource
Afficher la ressource

Les sessions sont essentielles à une bonne expérience utilisateur lors de l'utilisation du Web. Cependant, une gestion incorrecte des sessions peut entraîner des failles de sécurité que les attaquants peuvent exploiter.

Vous souhaitez en savoir plus ?

Jaap Karan Singh est un évangéliste du codage sécurisé, Chief Singh et cofondateur de Secure Code Warrior.

learn more

Secure Code Warrior est là pour aider votre organisation à sécuriser le code tout au long du cycle de développement logiciel et à créer une culture dans laquelle la cybersécurité est une priorité. Que vous soyez responsable de la sécurité des applications, développeur, responsable de la sécurité informatique ou toute autre personne impliquée dans la sécurité, nous pouvons aider votre organisation à réduire les risques associés à un code non sécurisé.

Réservez une démo
Partagez sur :
linkedin brandsSocialx logo
Auteur
Jaap Karan Singh
Published Jan 31, 2019

Jaap Karan Singh est un évangéliste du codage sécurisé, Chief Singh et cofondateur de Secure Code Warrior.

Partagez sur :
linkedin brandsSocialx logo

You navigate to a website and log in. As normal, you fill up your cart with products you'd like to buy. Then, whoops - your hand slips and closes the browser tab. After a minor panic, you enter the URL of the site back into the browser and hit the "Enter" key. You are brought back into the site, logged in, and all of your items are still in the cart. Whew.

How did the site know who you were without re-authenticating? It identified you because it was using sessions. Sessions are key to a good user experience when using the web. However, managing sessions incorrectly can lead to security holes that attackers can exploit.

Let's now review what session management means, how weak session management can hurt you, and what you can do to manage sessions properly.

Understanding Session Management Weaknesses

A session refers to a value stored on the server, specific to a single user of the application. This is necessary for two reasons: First, HTTP is a stateless protocol. Each request is separate and has no knowledge of requests that have come before or after it. A session helps the server track who sent the request. Otherwise, you would need to login every time you clicked on a button or a link.

The second reason for sessions is for authorization of the user. The session identifier can be used to recognize a specific user with specific rights within the system. The application will know who the person is and what they are allowed to do.

There are two components to a session. A data store on the server-side stores a session identifier and maps it to information about the user such as their user id or cart information. The same session identifier is sent to the browser in a cookie. The cookies are stored by the browser on the user's system. The client passes the cookie with each request, letting the server knows that this request is coming from the same user. Most applications use sessions to track users both pre- and post-authentication.

Proper session management is essential to the security of an application. A valid session ID has the same level of trust as a username/password, or even a second-factor authentication token.

Why Poor Session Management is Dangerous

Poor session management can lead to complete account takeover. This means customer data can be stolen, or products could be purchased fraudulently. There are several ways for attackers to obtain a valid session ID.

A session fixation attack occurs when sessions are not changed at key times, such as when a user logs into the system, and if session identifiers can be set using the URL. Setting session identifiers in this way may be used to keep users logged in across different applications that use the same authentication source. In this case, an attacker can browse to a website and gain a session ID. The attacker then sends a URL to an unsuspecting victim via email with the session ID in the URL. The victim clicks the URL in the email and logs into the website. If the session ID is not rotated upon login, the attacker now has a valid, authenticated session ID. This allows complete account takeover.

Another attack upon poor session management is a brute-force guessing attack. When developers try to create their own session management systems, often they use session IDs that are pretty simple to guess. These could be a sequence (1, 2, 3) or a predictable pattern of some kind. The attacker simply keeps guessing session IDs until a valid one is discovered. This also leads to an account takeover.

Sessions that aren't invalidated automatically after a certain amount of time has passed can be exploited to attack users. A successful cross-site request forgery attack depends on sessions that are still valid after the user leaves the site. Let's say an attacker places an iframe or image on a site visited by the user. The "src" (source) attribute is set to the URL of the vulnerable site and performs an action on behalf of the user. For example, a vulnerable banking application could be made to transfer money to an attacker's account without the user's permission.

Session management can be tricky, and weaknesses can be devastating. However, it's a well-known problem and it can be solved.

Defeat Insecure Session Management

Session management is a core piece of any web application. As a result, many web development frameworks have built-in session management functionality. These systems have been scrutinized by experts to find and weed out problems. Use them.

Some common properties of good session management include:

     Random session IDs generated that attackers can't guess

     Sessions are invalidated when a user logs out

     Sessions are invalidated automatically after a certain amount of time has passed

     Session IDs are changed after the user logs in

     Session IDs that are at least 128 bits long to prevent brute force attacks

Web frameworks such as Spring, ASP.NET Core, Rails, and Django have these properties and should be used for their higher security standards in this instance.

Bottom line: Don't create your own session management system from scratch.

Once the session IDs are created, they need to be protected. Set the Secure and HttpOnly flags to "true'on session cookies. This ensures that their value cannot be retrieved with JavaScript and the browser will only send the cookie via HTTPS, preventing attackers from stealing someone's session in transit.

Secure Your Sessions

Check out our free learning resources to find out more about secure session management. Learning how to secure your sessions will help prevent user account takeover, reputation damage, and lost revenue due to security breaches. Secure your sessions and keep your users safe.

Afficher la ressource
Afficher la ressource

Remplissez le formulaire ci-dessous pour télécharger le rapport

Nous aimerions avoir votre autorisation pour vous envoyer des informations sur nos produits et/ou sur des sujets liés au codage sécurisé. Nous traiterons toujours vos données personnelles avec le plus grand soin et ne les vendrons jamais à d'autres entreprises à des fins de marketing.

Soumettre
scw success icon
scw error icon
Pour soumettre le formulaire, veuillez activer les cookies « Analytics ». N'hésitez pas à les désactiver à nouveau une fois que vous aurez terminé.

You navigate to a website and log in. As normal, you fill up your cart with products you'd like to buy. Then, whoops - your hand slips and closes the browser tab. After a minor panic, you enter the URL of the site back into the browser and hit the "Enter" key. You are brought back into the site, logged in, and all of your items are still in the cart. Whew.

How did the site know who you were without re-authenticating? It identified you because it was using sessions. Sessions are key to a good user experience when using the web. However, managing sessions incorrectly can lead to security holes that attackers can exploit.

Let's now review what session management means, how weak session management can hurt you, and what you can do to manage sessions properly.

Understanding Session Management Weaknesses

A session refers to a value stored on the server, specific to a single user of the application. This is necessary for two reasons: First, HTTP is a stateless protocol. Each request is separate and has no knowledge of requests that have come before or after it. A session helps the server track who sent the request. Otherwise, you would need to login every time you clicked on a button or a link.

The second reason for sessions is for authorization of the user. The session identifier can be used to recognize a specific user with specific rights within the system. The application will know who the person is and what they are allowed to do.

There are two components to a session. A data store on the server-side stores a session identifier and maps it to information about the user such as their user id or cart information. The same session identifier is sent to the browser in a cookie. The cookies are stored by the browser on the user's system. The client passes the cookie with each request, letting the server knows that this request is coming from the same user. Most applications use sessions to track users both pre- and post-authentication.

Proper session management is essential to the security of an application. A valid session ID has the same level of trust as a username/password, or even a second-factor authentication token.

Why Poor Session Management is Dangerous

Poor session management can lead to complete account takeover. This means customer data can be stolen, or products could be purchased fraudulently. There are several ways for attackers to obtain a valid session ID.

A session fixation attack occurs when sessions are not changed at key times, such as when a user logs into the system, and if session identifiers can be set using the URL. Setting session identifiers in this way may be used to keep users logged in across different applications that use the same authentication source. In this case, an attacker can browse to a website and gain a session ID. The attacker then sends a URL to an unsuspecting victim via email with the session ID in the URL. The victim clicks the URL in the email and logs into the website. If the session ID is not rotated upon login, the attacker now has a valid, authenticated session ID. This allows complete account takeover.

Another attack upon poor session management is a brute-force guessing attack. When developers try to create their own session management systems, often they use session IDs that are pretty simple to guess. These could be a sequence (1, 2, 3) or a predictable pattern of some kind. The attacker simply keeps guessing session IDs until a valid one is discovered. This also leads to an account takeover.

Sessions that aren't invalidated automatically after a certain amount of time has passed can be exploited to attack users. A successful cross-site request forgery attack depends on sessions that are still valid after the user leaves the site. Let's say an attacker places an iframe or image on a site visited by the user. The "src" (source) attribute is set to the URL of the vulnerable site and performs an action on behalf of the user. For example, a vulnerable banking application could be made to transfer money to an attacker's account without the user's permission.

Session management can be tricky, and weaknesses can be devastating. However, it's a well-known problem and it can be solved.

Defeat Insecure Session Management

Session management is a core piece of any web application. As a result, many web development frameworks have built-in session management functionality. These systems have been scrutinized by experts to find and weed out problems. Use them.

Some common properties of good session management include:

     Random session IDs generated that attackers can't guess

     Sessions are invalidated when a user logs out

     Sessions are invalidated automatically after a certain amount of time has passed

     Session IDs are changed after the user logs in

     Session IDs that are at least 128 bits long to prevent brute force attacks

Web frameworks such as Spring, ASP.NET Core, Rails, and Django have these properties and should be used for their higher security standards in this instance.

Bottom line: Don't create your own session management system from scratch.

Once the session IDs are created, they need to be protected. Set the Secure and HttpOnly flags to "true'on session cookies. This ensures that their value cannot be retrieved with JavaScript and the browser will only send the cookie via HTTPS, preventing attackers from stealing someone's session in transit.

Secure Your Sessions

Check out our free learning resources to find out more about secure session management. Learning how to secure your sessions will help prevent user account takeover, reputation damage, and lost revenue due to security breaches. Secure your sessions and keep your users safe.

Afficher le webinaire
Commencez
learn more

Cliquez sur le lien ci-dessous et téléchargez le PDF de cette ressource.

Secure Code Warrior est là pour aider votre organisation à sécuriser le code tout au long du cycle de développement logiciel et à créer une culture dans laquelle la cybersécurité est une priorité. Que vous soyez responsable de la sécurité des applications, développeur, responsable de la sécurité informatique ou toute autre personne impliquée dans la sécurité, nous pouvons aider votre organisation à réduire les risques associés à un code non sécurisé.

Afficher le rapportRéservez une démo
Télécharger le PDF
Afficher la ressource
Partagez sur :
linkedin brandsSocialx logo
Vous souhaitez en savoir plus ?

Partagez sur :
linkedin brandsSocialx logo
Auteur
Jaap Karan Singh
Published Jan 31, 2019

Jaap Karan Singh est un évangéliste du codage sécurisé, Chief Singh et cofondateur de Secure Code Warrior.

Partagez sur :
linkedin brandsSocialx logo

You navigate to a website and log in. As normal, you fill up your cart with products you'd like to buy. Then, whoops - your hand slips and closes the browser tab. After a minor panic, you enter the URL of the site back into the browser and hit the "Enter" key. You are brought back into the site, logged in, and all of your items are still in the cart. Whew.

How did the site know who you were without re-authenticating? It identified you because it was using sessions. Sessions are key to a good user experience when using the web. However, managing sessions incorrectly can lead to security holes that attackers can exploit.

Let's now review what session management means, how weak session management can hurt you, and what you can do to manage sessions properly.

Understanding Session Management Weaknesses

A session refers to a value stored on the server, specific to a single user of the application. This is necessary for two reasons: First, HTTP is a stateless protocol. Each request is separate and has no knowledge of requests that have come before or after it. A session helps the server track who sent the request. Otherwise, you would need to login every time you clicked on a button or a link.

The second reason for sessions is for authorization of the user. The session identifier can be used to recognize a specific user with specific rights within the system. The application will know who the person is and what they are allowed to do.

There are two components to a session. A data store on the server-side stores a session identifier and maps it to information about the user such as their user id or cart information. The same session identifier is sent to the browser in a cookie. The cookies are stored by the browser on the user's system. The client passes the cookie with each request, letting the server knows that this request is coming from the same user. Most applications use sessions to track users both pre- and post-authentication.

Proper session management is essential to the security of an application. A valid session ID has the same level of trust as a username/password, or even a second-factor authentication token.

Why Poor Session Management is Dangerous

Poor session management can lead to complete account takeover. This means customer data can be stolen, or products could be purchased fraudulently. There are several ways for attackers to obtain a valid session ID.

A session fixation attack occurs when sessions are not changed at key times, such as when a user logs into the system, and if session identifiers can be set using the URL. Setting session identifiers in this way may be used to keep users logged in across different applications that use the same authentication source. In this case, an attacker can browse to a website and gain a session ID. The attacker then sends a URL to an unsuspecting victim via email with the session ID in the URL. The victim clicks the URL in the email and logs into the website. If the session ID is not rotated upon login, the attacker now has a valid, authenticated session ID. This allows complete account takeover.

Another attack upon poor session management is a brute-force guessing attack. When developers try to create their own session management systems, often they use session IDs that are pretty simple to guess. These could be a sequence (1, 2, 3) or a predictable pattern of some kind. The attacker simply keeps guessing session IDs until a valid one is discovered. This also leads to an account takeover.

Sessions that aren't invalidated automatically after a certain amount of time has passed can be exploited to attack users. A successful cross-site request forgery attack depends on sessions that are still valid after the user leaves the site. Let's say an attacker places an iframe or image on a site visited by the user. The "src" (source) attribute is set to the URL of the vulnerable site and performs an action on behalf of the user. For example, a vulnerable banking application could be made to transfer money to an attacker's account without the user's permission.

Session management can be tricky, and weaknesses can be devastating. However, it's a well-known problem and it can be solved.

Defeat Insecure Session Management

Session management is a core piece of any web application. As a result, many web development frameworks have built-in session management functionality. These systems have been scrutinized by experts to find and weed out problems. Use them.

Some common properties of good session management include:

     Random session IDs generated that attackers can't guess

     Sessions are invalidated when a user logs out

     Sessions are invalidated automatically after a certain amount of time has passed

     Session IDs are changed after the user logs in

     Session IDs that are at least 128 bits long to prevent brute force attacks

Web frameworks such as Spring, ASP.NET Core, Rails, and Django have these properties and should be used for their higher security standards in this instance.

Bottom line: Don't create your own session management system from scratch.

Once the session IDs are created, they need to be protected. Set the Secure and HttpOnly flags to "true'on session cookies. This ensures that their value cannot be retrieved with JavaScript and the browser will only send the cookie via HTTPS, preventing attackers from stealing someone's session in transit.

Secure Your Sessions

Check out our free learning resources to find out more about secure session management. Learning how to secure your sessions will help prevent user account takeover, reputation damage, and lost revenue due to security breaches. Secure your sessions and keep your users safe.

Table des matières

Télécharger le PDF
Afficher la ressource
Vous souhaitez en savoir plus ?

Jaap Karan Singh est un évangéliste du codage sécurisé, Chief Singh et cofondateur de Secure Code Warrior.

learn more

Secure Code Warrior est là pour aider votre organisation à sécuriser le code tout au long du cycle de développement logiciel et à créer une culture dans laquelle la cybersécurité est une priorité. Que vous soyez responsable de la sécurité des applications, développeur, responsable de la sécurité informatique ou toute autre personne impliquée dans la sécurité, nous pouvons aider votre organisation à réduire les risques associés à un code non sécurisé.

Réservez une démoTélécharger
Partagez sur :
linkedin brandsSocialx logo
Centre de ressources

Ressources pour vous aider à démarrer

Plus de posts
Centre de ressources

Ressources pour vous aider à démarrer

Plus de posts