Beta

Create a tenant

A new tenant starts with its own users, OAuth settings, audit history and logs. You are its first Tenant Admin.

Staying signed in

A sign-in is followed by many separate requests. A session lets an application connect those requests to the account that authenticated, while continuing to check whether the session and requested access are valid.

Remembering a sign-in

Ava signs in to the photo application and opens an album. Then she opens another album, changes its title, and visits her account settings. The application does not ask for her password on every page. Somehow, it connects these separate requests to the sign-in it accepted a moment ago.

That continuity is a session. HTTP does not remember Ava by itself. The application needs a way to recognize a later request, find the account it belongs to, and decide whether to keep accepting it.

The application connects separate requests through a session.

A session in practice

In one common design, the server creates a session record after sign-in. It records the account and the session's lifetime, then gives the browser a randomly generated, unpredictable identifier. The identifier points to the record; it does not need to contain Ava's password or profile.

The identifier travels in a cookie: a small named value that a server asks the browser to keep, using a Set-Cookie header in a response. On later requests to the same place, the browser sends the cookie back by itself in a Cookie header. The server looks up the session and finds Ava's account. That explains how opening a second album can work without another password prompt.

A session identifies the ongoing interaction. Authorization still checks each action.

Using and protecting a session

Recognizing Ava's session is only the beginning of a request. The server must also check that the session remains valid and that Ava can perform the action she requested. Signing in once does not give her access to every album.

There is another problem at the moment of sign-in. Many applications start a session before anyone signs in, to remember a language choice or what is in a basket. Suppose an attacker starts one of these anonymous sessions, notes its identifier, and gets Ava's browser to use it. A page on a name under photos.example that the attacker controls could do that by setting a cookie for the whole domain. If the server keeps that identifier when Ava signs in, the attacker may be able to use the same value to act as Ava. This is session fixation.

To prevent that handover, the application issues a new, unpredictable identifier when authentication succeeds and stops accepting the old one. Replacing the cookie in Ava's browser is only half the job; the server must reject the previous value too.

For a sensitive change, such as replacing a password, the application may ask Ava to authenticate again. That produces fresh evidence of control. Merely changing a session identifier does not.

Replacing the identifier helps prevent session fixation.
Optional detail: replacing the identifier at sign-in

These readable values are placeholders; real session identifiers must be randomly generated and unpredictable. Before sign-in, the browser sends:

Cookie: __Host-session=OLD_ANONYMOUS_ID

After verifying the credentials, the server creates a new session associated with the account, invalidates the old identifier, and replaces the browser's cookie:

Set-Cookie: __Host-session=NEW_AUTHENTICATED_ID; Path=/; Secure; HttpOnly; SameSite=Lax

Subsequent requests use NEW_AUTHENTICATED_ID, and OLD_ANONYMOUS_ID no longer grants access. Most web frameworks, the libraries applications are built with, include session management that can make this change; check that yours does.

Ending a session

Later, Ava walks away from her computer. An idle timeout can end her session after a period without activity. An absolute timeout limits the total session lifetime even if she keeps using it. A service chooses these limits according to what it protects and may renew sessions under its own rules.

When Ava chooses Sign out, the server-stored design we followed needs to invalidate the session record and remove the browser's cookie. Otherwise, a copied cookie could still point to a session the server accepts.

Closing a browser is less definite. A browser may restore its cookies when it reopens, and an old page may remain visible after a session ends. The useful question is whether the server accepts the next protected request.

So far, one application has managed this continuity on its own. Once sign-in happens at a separate service, that service keeps a session too, and the two sessions can end at different times.

Clearing a browser cookie alone does not invalidate another copy.

Check your understanding

Try these questions before moving on. If an answer isn't right, use the feedback and try again.

Someone knows Ava's anonymous session identifier before she signs in. What prevents that value becoming a route into her signed-in account? 1 of 3

Choose one answer.

Ava signs out. Her browser removes its cookie, but the server leaves the session valid. Why is that a problem? 2 of 3

Choose one answer.

An attacker's script hidden in a photo comment runs when Ava views the page. Which cookie attribute keeps it from copying her session cookie? 3 of 3

Choose one answer.

Try it in the Lab

We value your privacy

We use cookies and similar technologies to enhance your browsing experience, and analytics to understand our traffic. By clicking "Allow all", you consent to optional analytics. Cookie Policy

Learn identity