Contact Us Today 01642 716680

Session Cookie

Definition: A session cookie, also known as a transient cookie, is a cookie which is designed to store information about a user's browsing session and is deleted after the session ends, typically when the web browser is closed.

A session cookie is an integral part of session management in web applications. Unlike persistent cookies, which are stored on a user’s device for a fixed duration, session cookies are temporary and store session-specific data such as selections made or items added to a shopping cart. They are used to maintain state across multiple pages of an application and provide a seamless user experience, without requiring users to re-enter information on every page.

In cyber security, the correct implementation of session cookies is essential for maintaining secure sessions. These cookies should be marked as secure, meaning they can only be transmitted over encrypted connections (HTTPS), and flagged as HttpOnly, which prevents access to the cookie via client-side scripts, mitigating the risk of cross-site scripting (XSS) attacks. Additionally, steps should be taken to ensure that session cookies are properly invalidated and destroyed upon logout or after the session has expired to prevent session fixation and session replay attacks.

Secure handling of a session cookie is critical because they often hold session IDs, which if compromised, can lead to session hijacking whereby an attacker takes over a user’s session. Therefore, robust measures such as strong session management practices, including generation of unpredictable session identifiers and good cookie management policies, must be followed to prevent unauthorised access to user sessions.

Key Characteristics:

  • Temporary and deleted after the web browser is closed
  • Stores session-specific information for the duration of the session
  • Should be secured with the ‘Secure’ and ‘HttpOnly’ attributes
  • Does not persist on the user’s device beyond the single session

Examples:

  • Real-World Example: An online retailer’s website uses session cookies to keep track of a user’s shopping cart as they navigate from page to page. When the user checks out or closes the browser, the session cookie is deleted.
  • Hypothetical Scenario: A user logs into a web application. The server creates a session cookie with a unique session ID and marks it as Secure and HttpOnly. This ensures that the session ID is only sent over HTTPS connections and is not accessible via JavaScript, reducing the risk of unintentional disclosure.

Related Terms:

  • Session Management: The overarching process of managing user state on a web application, including the use of session cookies.
  • Secure Attribute: An attribute that can be set on cookies to ensure they are sent over secure channels such as HTTPS.
  • HttpOnly Attribute: An attribute that can be set on cookies to prevent client-side scripts from accessing the cookie data.
  • Cross-Site Scripting (XSS): A security vulnerability that could lead to unauthorised access to session cookies if they are not properly secured.

What is the OWASP Top 10: Download our flash cards to find out.

Inside you will find a description of the most common web vulnerabilities.

Contact us

Get a free, no obligation quote from one of our expert staff.