Written by: Mio Kanzaki(Security Analyst (AI))Reviewed by: 千葉圭介Updated
A session is the series of usage from login to the end. OWASP describes it as a chain of HTTP requests and responses tied to the same user. The reason you can move between screens while logged in on a member site is that this state continues.
How does a session work?
Take a hotel stay as an example. At check-in you are handed a card with a room number, and until check-out you come and go with that card. On a site, login is check-in and logout is check-out. The mark that corresponds to the card is called the session ID.
According to OWASP, a session ID is a pair of a name and a value, shared between the user and the site with every request. The value is only a mark and must not contain sensitive information such as personal data. When creating one, use a random number that is hard to guess.
Web communication, as it is, does not remember the previous time. RFC 6265 says that with cookies a server can keep a continuing state even on top of stateless communication. The explanation of the container that carries the mark is in cookie. Failures in managing logged-in state are set out in session management flaws. To have your own setup reviewed, contact us.
Why does a session matter?
If someone else learns the session ID, that person can impersonate the user. The site can only look at whether the mark is genuine. For that reason, how the mark is made and how it is protected matter.
OWASP makes regenerating the session ID right after login required. This is to prevent session fixation, the attack that makes someone use a decided ID. At logout, it asks that at least on the server side, the IDs issued within the same login be invalidated together.
The idea of expiry is set out in session timeout. An operator of a member site checks these points.
- Create the mark with a random number that is hard to guess.
- Regenerate the session ID right after login.
- Expire the session on the server when inactivity continues.
- At logout, invalidate the server-side session.
- Put settings such as Secure on the cookie that holds the logged-in state.
Related terms
- Cookie: a small record saved in the browser
- Session timeout: a mechanism that logs out automatically after a period without activity
- Session hijacking: an attack that steals a logged-in state to impersonate the person
- Session fixation: an attack that makes someone use a fixed ID, leading to takeover
Frequently asked questions
Are a session and a cookie the same thing?
No. A session is the usage state from login to the end. A cookie is one container that holds and carries that mark. RFC 6265 says that with cookies a server can keep a continuing state.
Why regenerate the session ID at every login?
To prevent session fixation. OWASP makes regenerating the session ID required where privileges change, such as at login. It avoids an ID the attacker decided beforehand continuing to be used after login.
Next step
To start reviewing how logged-in state is managed, read session management flaws. The free URL check shows only what is visible from outside your member site, and for help with how it is built, contact us.
Frequently asked questions
Are a session and a cookie the same thing?
No. A session is the usage state from login to the end. A cookie is one container that holds and carries that mark. RFC 6265 says that with cookies a server can keep a continuing state.
Why regenerate the session ID at every login?
To prevent session fixation. OWASP makes regenerating the session ID required where privileges change, such as at login. It avoids an ID the attacker decided beforehand continuing to be used after login.