NETLEARN
Lesson 01Identity

Cookies & Login Sessions

HTTP keeps no memory between requests. So how does the server know you are logged in? The answer is two small things: a cookie in the browser and a session behind it.

Layer
Layer 7 · Application
Reference
RFC 6265 (cookie)
Steps
7
Browserholds the cookie
Web servercreates the session
Session storememory / DB
legendrequestcontrolresponsemessage in flight

Common misunderstandings

  • A cookie without Secure can leak over an unencrypted network; without HttpOnly, a single XSS hole is enough to steal the login session.

Key notes

Cookie vs session
The cookie lives in the browser (the key); the session lives on the server (the content). Anything sensitive stays on the server.
HttpOnly
The cookie cannot be read by JavaScript. This is important so that XSS cannot steal the session.
SameSite
Limits the cookie from being sent on requests from other sites. Holds back CSRF.
Stateless alternative
JWT puts the data inside the token itself, but it is hard to revoke before it expires.