Session Token

Session Token Definition
A session token is a unique string of characters assigned to a user after they first open or log in to a website or app. The token is stored on the user’s device, and the site’s server checks it to verify their identity every time the user makes a request. That way, the user doesn’t have to enter their password every time.
Not every site issues session tokens, but most do. They’re typically used by sites that need to personalize the user’s experience or track their activity. For example, online stores associate the items in a customer’s cart with their session token. This allows them to maintain the cart across different webpages even if the user isn’t logged in.
How Session Tokens Work
1. The user visits a website, starting a session.
2. The site generates a unique session token and assigns it to that user. Most sites will also generate a new token if the user logs in, either creating a new session or merging it with the old session.
3. A copy of the session token is stored on the user’s device, typically inside a tracking cookie. Another copy is stored on the server itself.
4. The browser attaches the session token to every subsequent request the user makes on the site, like opening a new page.
5. The server verifies the attached token. It checks a list of active sessions to confirm the user’s identity.
6. The site keeps track of user activity, like the contents of a shopping cart, by assigning it to the stored session token.
Session Token Properties
- Temporary: The server copy of the session token is deleted when the user logs out or remains inactive for a preset period of time. The server rejects any further requests made with that token attached. The user has to log in again or start a new session to generate a new session token.
- Unique: Each active session has a different token associated with it. Sites can use browser fingerprinting or the visitor’s IP address to ensure it’s the same visitor with the same token. This makes it harder for a cybercriminal to hijack the session and gain access to someone’s account (even with a stolen session token).
- Random: Website session tokens are usually randomly generated (“opaque”). They typically don’t contain any data that could be used to identify the session user. However, some sites, apps, and APIs (Application Programming Interfaces) also use a type of token called a JWT (JSON Web Token). These can contain identifiable information like user IDs.
- Secured: Various flags are attached to the session token. They can signal the browser to encrypt the transmission of the token by only sending it over HTTPS, or prevent JavaScript from accessing the cookie. This makes it more difficult for potential cybercriminals to get a user’s session token.
Read More
FAQ
The server issues a session token, and the browser typically stores it in a cookie associated with that website. Another copy of the session token exists on the server itself. The server keeps it in a database of active session tokens and user accounts or unique visiting users. It can invalidate and delete the token when the user logs out or if a predetermined amount of time passes without user activity.
No, a session token and a cookie are not the same thing. A cookie is a small file stored by the browser on the user’s device. Websites create cookies to store data to be used during a future session, like login status. A session token is a string of characters used to uniquely identify users visiting the site. The browser typically stores a site’s session token inside the cookie associated with that site.
Yes, but it’s unlikely. Typically, the server randomly generates session tokens, and they don’t have elements that could be used by third parties to identify the user. Also, servers usually add security flags to the token. They tell the browser to apply security rules, like only sending the token over secure HTTPS.
