Login
ChallengesLearn
Scoreboard
Teams
Profile

Preferences

Truesapiens

LearnAccess ControlSession Management
Access Control·Lesson 10 of 12

Session Management

Cookies, session tokens, secure flags, rotation after login. How servers bind an authenticated user to a browser — and how session fixation, predictable tokens, and missing HttpOnly break that binding.

Intermediate14 min
Access ControlSessionCookies
Loading lesson…
PreviousRate Limit & Auth BypassNextAccess Control Case Studies

© 2026 Truesapiens.

Terms of ServicePrivacy PolicyCookie Policy

Session management is the mechanism by which a server maintains state across stateless HTTP requests. After authentication, the server issues a session token — typically stored in a cookie — that the browser sends with every subsequent request. How that token is generated, stored, transmitted, and invalidated determines whether the session can be stolen or forged.

What you'll be able to do
  • Explain how session tokens bind an authenticated user to a browser session.
  • Identify the Secure, HttpOnly, and SameSite cookie flags and their role in mitigating specific attacks.
  • Describe session fixation and why token rotation after login is essential.
  • Analyse the 2016 Slack session fixation vulnerability.
Key terms
Session token
A cryptographically random identifier issued by the server after authentication, stored in a cookie or local storage, and sent with each request to identify the session.
HttpOnly flag
A cookie attribute that prevents client-side JavaScript from accessing the cookie via document.cookie — the primary defence against XSS-based session theft.
SameSite flag
A cookie attribute that controls whether the cookie is sent with cross-origin requests. Strict, Lax (default), and None values determine the browser's behaviour.
Session fixation
An attack where the attacker sets or pre-selects a victim's session ID before the victim authenticates, then hijacks the session after login (CWE-384).
What is it?

The token that proves who you are

HTTP is stateless — each request carries no memory of previous requests. To remember that a user has logged in, the server issues a session token, a random string stored in a cookie. The browser sends it automatically on every request, and the server looks it up in its session store to determine the user's identity and permissions.

The security of this system depends entirely on keeping the token secret. If an attacker can steal or predict the token, they can impersonate the user without knowing their password. Cookie flags — Secure, HttpOnly, and SameSite — are the standard defences that gate different attack vectors.

Session lifecycle flow
Mini Map
Press enter or space to select a node. You can then use the arrow keys to move the node around. Press delete to remove it and escape to cancel.
Press enter or space to select an edge. You can then press delete to remove it or escape to cancel.
Try it

Inspect session cookies in the dev tools panel

The sandbox below simulates a browser DevTools-style cookie inspector. You can toggle Secure, HttpOnly, and SameSite flags on a session cookie and immediately see whether three common attacks — XSS cookie theft, Man-in-the-Middle sniffing, and Cross-Site Request Forgery — succeed or fail against your chosen configuration.

devsession-inspector.local/cookies
session-inspector
Session cookie: connect.sid
connect.sid=s%3A8f3a...
Secure=trueHttpOnly=trueSameSite=Lax
Presets
Real-world relevance

Slack session fixation (2016)

In 2016, a security researcher discovered a session fixation vulnerability in Slack. The attacker could craft a link containing a pre-set session ID:https://slack.com/login?session_id=ATTACKER_SET_ID. If the victim clicked the link and logged in, Slack would reuse the attacker-supplied session ID instead of generating a new one after authentication. The attacker already knew the session ID and could hijack the session immediately after login.

The fix was straightforward: regenerate the session token on the server after every successful login — a practice called “session rotation”. Slack also added HttpOnly and Secure flags to their session cookie to prevent XSS-based theft and MitM sniffing. The case remains a textbook example of why a single missing flag or rotation step can undermine the entire authentication system.

Mitigation

Flags, rotation, and server-side enforcement

Three defences work together to protect session tokens. Cookie flags control what the browser does with the token. Session rotation ensures that a stolen pre-authentication token cannot be used after login. Server-side binding ties the token to specific client attributes.

javascriptvulnerable
// VULNERABLE - missing flags and no rotation
res.setHeader('Set-Cookie', `session=${token}; Path=/`);
// No Secure — sent over HTTP
// No HttpOnly — readable by JavaScript
// No SameSite — sent on cross-origin requests

// SAFE - flags + rotation after login
app.post('/api/login', async (req, res) => {
  const user = await authenticate(req.body);
  if (!user) return res.status(401).end();

  // Regenerate token after login (prevents fixation)
  const newToken = crypto.randomBytes(32).toString('hex');
  await sessionStore.create(newToken, user.id);

  res.setHeader('Set-Cookie', [
    `session=${newToken}; Path=/;`,
    'HttpOnly;',           // blocks document.cookie
    'Secure;',             // TLS only
    'SameSite=Lax',        // blocks CSRF from external sites
    'Max-Age=86400',       // 24h expiry
  ].join(' '));
  res.json({ ok: true });
});

// SAFER - bind session to client fingerprint
app.use((req, res, next) => {
  const token = parseCookie(req, 'session');
  const session = await sessionStore.get(token);
  if (session && session.fingerprint !== fingerprint(req)) {
    sessionStore.destroy(token);
    return res.status(401).end();
  }
  next();
});

Additional measures: set short session expiry times, invalidate sessions on password change, store sessions server-side rather than in JWTs where revocation is impossible, and consider binding sessions to a client fingerprint (IP + User-Agent hash) as a defence-in-depth layer.

Further reading
  • CWE-384: Session Fixation(MITRE)
  • Mozilla Developer Network — Set-Cookie(MDN)
  • Slack Session Fixation Disclosure (2016)(HackerOne)
Key takeaways

What to remember

  • Session tokens are the keys to the kingdom — if stolen, the attacker can impersonate the user without knowing their password.
  • HttpOnly prevents XSS-based theft; Secure prevents MitM sniffing; SameSite prevents CSRF. Use all three.
  • Rotate session tokens after every privilege escalation event: login, role change, password reset.
  • Session fixation is prevented by always generating a fresh token on the server after authentication, never reusing a client-supplied ID.
  • Bind sessions to a client fingerprint as defence-in-depth, but never rely on fingerprinting alone — IPs change, User-Agents are shared.

Knowledge check

0/3 answered · 0 correct
  1. 1.Which cookie flag prevents JavaScript from reading the session token via document.cookie?

  2. 2.What is session rotation and why is it necessary?

  3. 3.An application sets Set-Cookie: session=abc123; Path=/; Secure. What attacks is it still vulnerable to?