What is Session?
Updated: Oct 28

A session is a period during which a system keeps track of an ongoing interaction with a user, application or device. It lets related actions be treated as part of the same activity, even when they involve multiple separate requests or connections.
When you sign in to a website and move between pages without entering your password each time, the website usually maintains an authenticated session. Other sessions can exist before sign-in, and the term also applies to remote access and network protocols. The exact start, lifetime and end depend on the system involved.
Why do websites use sessions?
HTTP is a stateless protocol: the meaning of a request can be understood independently of earlier requests. The HTTP semantics specification, RFC 9110, describes this design. A website can still maintain application state across requests by using a session mechanism.
For example, a shopping site may keep track of a basket while a visitor browses. A support portal may remember that a user has signed in and associate subsequent requests with that user's session. The server must still check whether each requested action is permitted.
The illustration shows a simplified server-managed web session: the user signs in, the server creates a session, the browser presents its session identifier with later requests, and the session ends on expiry or logout.

A user visits an application and, where needed, signs in.
The application establishes a session and associates it with the appropriate state.
The browser receives a session identifier, commonly in a cookie.
The browser sends the eligible cookie on later requests to the application.
The server looks up and checks the session, then applies access rules for the requested action.
The session ends when the server invalidates it, it expires or another configured condition occurs.
This is one common design, not the only way to manage a session. A site may create an anonymous session before login, rotate its identifier when authentication succeeds, or use a different architecture.
What is a session ID?
A session ID is a value used to associate a request with a particular session. In a typical server-managed design, the browser holds the identifier while the application keeps associated state in a server-side store. The identifier itself should be unpredictable and treated as sensitive because someone who obtains a valid authenticated session ID may be able to impersonate the user.
The identifier is not the same thing as a person's username or password, and it should not contain information that needs to remain secret merely by virtue of its encoding. The server must check that the identifier is valid and that the session has not expired or been revoked.
The OWASP session management guidance describes secure identifier generation, cookie attributes, renewal and server-side expiry. Use a maintained framework's session mechanism and configure it for the application's requirements.
Sessions and cookies
A cookie is a browser mechanism for storing a value and sending it with eligible requests according to its scope and attributes. A session is the ongoing interaction or associated application state. A cookie can carry a session ID, but not every cookie represents a session and not every session uses a cookie.
Item | What it does | Important distinction |
|---|---|---|
Session | Maintains an ongoing application relationship or state | May exist before or after authentication |
Session ID | Identifies a particular session to the application | Can be a sensitive bearer credential |
Cookie | Stores and sends a value under browser rules | Can hold a session ID or another value |
Persistent cookie | Has an expiry or maximum age that can outlast a browser session | Does not guarantee the server session remains valid |
Session cookie | Has no explicit expiry or maximum age | Browser session restore can affect when it is removed |
Cookie attributes matter. Secure restricts transmission to secure connections under browser rules; HttpOnly prevents JavaScript from reading the cookie directly; and SameSite controls when a cookie is sent with certain cross-site requests. These attributes reduce particular risks but do not replace HTTPS, protection against cross-site scripting or suitable cross-site request forgery defences. See MDN's HTTP cookie guide for the browser behaviour and attributes.
A browser's cookie lifetime and the server's session lifetime are separate. A cookie can still be present after the server has expired or revoked the session. Conversely, deleting a cookie from one browser does not necessarily invalidate the corresponding server-side session everywhere.
How long does a session last?
There is no universal session length. An application may impose an idle timeout after a period without qualifying activity, an absolute timeout after a maximum lifetime, or both. It may also require fresh authentication for a sensitive action or after a risk event.
A timeout protects an unattended account, but an overly short setting can interrupt work. A longer setting may be convenient while increasing exposure if a device or session credential is compromised. Choose values based on the service, sensitivity, user needs and applicable requirements, then test the behaviour rather than assuming that a browser closing or a cookie disappearing ends every server-side session.
A session expiry is separate from a network disconnection. A temporary internet outage may interrupt requests while the session remains valid on the server. If the session expires during the outage, the user may need to sign in again when connectivity returns. Whether unsaved work survives depends on the application's design.
Session, connection and token: what is the difference?
Term | Meaning | Example |
|---|---|---|
Application session | Ongoing interaction tracked by an application | A user signed in to a support portal |
Network connection | Communication channel between endpoints | A TCP connection used to send requests |
Session ID | Value associating requests with an application session | An opaque identifier in a cookie |
Access token | Credential presented to an intended resource | A client calling a protected API |
JWT | A format that can carry claims | A signed token used under a specific profile |
One application session can continue across several network connections. One connection can carry multiple requests and, depending on the protocol and intermediaries, should not be assumed to identify a single user. A network connection ending does not automatically mean the application session has ended.
Token based authentication covers how tokens can support a trusted relationship. A JWT is a claims format, not the session itself. Some systems use JWTs in their session designs, while others use opaque identifiers and server-side state.
Authentication, SSO and separate sessions
Authentication verifies a claimed identity or credential. A session can then maintain the resulting authenticated state, subject to expiry, reauthentication and access rules. An anonymous visitor can also have a session, so the existence of a session does not prove a user has signed in.
With single sign on, an identity provider and connected applications can maintain separate sessions. Signing out of one application does not necessarily end the identity provider's session or all other application sessions. The result depends on supported logout mechanisms, configuration and the participating applications.
A valid session does not grant permission to every resource. The application must check the requested action and the user's current permissions, including customer or tenant boundaries where relevant.
What happens when you log out?
A secure logout process should end the relevant application session on the server and remove or expire the associated browser cookie where applicable. Ending only the visible browser state may leave a copied session identifier usable if the server still accepts it.
The effects on other devices, identity-provider sessions, access tokens and refresh tokens depend on the implementation. A “log out everywhere” feature must be designed and tested across those components. Do not assume that closing a browser, removing a cookie or revoking one token has identical effects.
Applications should also renew the session identifier after authentication and other relevant privilege changes to reduce session fixation risks. Avoid passing session identifiers in URLs, where they can leak into logs, browser history or referrer information.
Common session security risks
Session hijacking: an attacker obtains a valid session credential and reuses it.
Session fixation: an attacker causes a user to authenticate with a session identifier the attacker already knows.
Cross-site scripting: malicious script runs in the application's context and may access sensitive data or act as the user.
Cross-site request forgery: a browser is induced to send an unwanted authenticated request where protections are inadequate.
Inadequate expiry or logout: sessions continue longer than intended or are not invalidated correctly.
Excessive access: a valid session is treated as permission to access another user's data.
Protect the complete application, not just the cookie. Use HTTPS throughout, secure session identifiers and storage, appropriate cookie settings, server-side expiry, access checks, monitoring and tested incident procedures. HttpOnly limits direct JavaScript access to a cookie but does not stop malicious script from making requests in an affected user's session.
A practical UK example
Imagine an engineer at a UK support business signs in to a customer portal. This is an illustrative example, not a tested system or a claim about a specific provider.
The portal creates a server-managed session and issues a session cookie. The engineer opens several customer cases, and each request is checked against the session and the engineer's permissions. An idle timeout requires a fresh sign-in after the configured period without qualifying activity.
Situation | Intended result | What to test |
|---|---|---|
Engineer opens an assigned case | Allow if the session and permissions are valid | Session lookup and customer access rules |
Engineer opens another customer's case | Deny unless explicitly permitted | Tenant and object-level authorisation |
Laptop loses its connection briefly | Resume if the session remains valid | Reconnection and unsaved work behaviour |
Engineer signs out | End the portal session | Server-side invalidation and cookie removal |
Engineer's account is disabled | Remove access according to policy | Active sessions, connected systems and caches |
The portal's session, the identity provider's session and any API tokens may have different lifetimes. The organisation should test the complete access-removal process rather than assuming a single logout action covers everything.
How to troubleshoot session problems
Repeated sign-in: check whether the server session expires, cookies are blocked or the application's clock or domain settings are wrong.
Unexpected logout: check idle and absolute timeouts, account changes, security events and server-side invalidation.
Sign-in works on one device but not another: check browser settings, cookie scope, extensions and device-specific configuration.
Session disappears during deployment: check whether the session store or signing keys are shared and retained correctly across instances.
Logout appears incomplete: check separate application, identity-provider and API token lifecycles.
A different user sees data: investigate session isolation and authorisation immediately using the organisation's incident procedures.
Use authorised test accounts and non-sensitive data. Capture timestamps, safe request identifiers and the observed steps. Never send a live session cookie or identifier in a public support request or screenshot.
How to review a session design
Identify where session state is stored and how the client presents the identifier.
Check identifier generation, transport, cookie scope and security attributes.
Confirm identifier renewal after authentication and privilege changes.
Test idle and absolute expiry, reauthentication and logout on the server.
Check access controls for individual users, actions and customer resources.
Test multiple devices, service restarts, network interruptions and connected identity systems.
Confirm that logs and support workflows do not expose session credentials.
A successful login is only one test. Also verify that invalid, expired, revoked and unauthorised requests are rejected and that the system handles failures without exposing another user's information.
Key takeaway
A session lets a system maintain an ongoing interaction across related activity. A secure session depends on how its identifier is created and protected, how long the session lasts, how it ends and whether the application checks permissions on each request.
Frequently asked questions
What is a session?
A session is an ongoing interaction that a system tracks across related activity for a user, application or device.
Is a session the same as a cookie?
No. A session is the tracked interaction or state. A cookie is a browser mechanism that can carry a session identifier or another value.
Does a session mean I am signed in?
Not always. Websites can maintain anonymous sessions before a user authenticates. A shopping basket or preferences can be associated with an anonymous visitor. After sign-in, the service must bind the session to the correct identity and enforce the permissions for each action. Having a session identifier alone does not establish authenticated access.
Does closing my browser always end a session?
No. Browser behaviour, cookie persistence and server-side session policies differ. Use the application's logout function when you need to end a session.
Does a lost internet connection end my session?
Not necessarily. A session can remain valid during a temporary disconnection, although it may expire or be revoked while the connection is unavailable.
Can someone use a stolen session ID?
A valid session identifier can often be reused by someone who obtains it. Protect it and invalidate affected sessions if compromise is suspected.
Does logging out of one application log me out everywhere?
Not necessarily. Applications, identity providers and tokens can have separate sessions and lifecycles. Wider logout depends on the system's implementation.

