Copyright (c) 2026 MindMesh Academy. All rights reserved. This content is proprietary and may not be reproduced or distributed without permission.

6.3.2. SSO, JIT Provisioning, and Trust Relationships

💡 First Principle: A session token is a temporary credential that represents an authenticated state. If an attacker obtains a valid session token, they inherit the authentication and authorization of the legitimate user — without needing to know their password. Session management is the set of controls that prevent session tokens from being stolen, guessed, or abused.

Session token requirements:
RequirementWhyImplementation
Cryptographically randomUnpredictable; cannot be guessed128+ bits of entropy from CSPRNG
Sufficient lengthBrute force infeasible128 bits minimum
Bound to user identityToken not transferable to another userServer-side session store; token validated against user on each request
Transmitted securelyCannot be interceptedHTTPS only; Secure cookie flag
Not accessible to scriptsXSS cannot steal the tokenHttpOnly cookie flag
Bounded lifetimeLimits exposure windowIdle timeout + absolute timeout
Invalidated on logoutCannot be reused after logoutServer-side session store deletion
Session attack types:

Session fixation: Attacker sets a session ID (before authentication) and tricks the user into authenticating with that ID. After authentication, the session is associated with the legitimate user, but the attacker knows the session ID. Defense: generate a new session ID upon successful authentication.

Session hijacking: Attacker steals a valid session token (XSS, network sniffing, predictable token). Uses it to impersonate the user. Defense: HttpOnly + Secure cookie flags; HTTPS; short token lifetime; re-authentication for sensitive operations.

Cross-Site Request Forgery (CSRF): Attacker tricks the user's browser into sending an authenticated request to a site the user is logged into. The request carries the session cookie automatically. Defense: CSRF tokens (anti-forgery tokens) in forms; SameSite cookie attribute; verify Origin/Referer headers.

Cookie security flags:
FlagEffectRequired For
SecureCookie sent only over HTTPSAll session cookies
HttpOnlyCookie not accessible to JavaScriptSession tokens (prevents XSS theft)
SameSite=StrictCookie not sent with cross-site requestsCSRF prevention
SameSite=LaxCookie sent with top-level navigation but not cross-site subresource requestsBalance of CSRF protection and usability
Token-based authentication (JWT):

JSON Web Tokens (JWT) are stateless session tokens: they contain claims (user identity, roles, expiration) encoded in a signed (and optionally encrypted) format. The server validates the signature without querying a session store.

JWT structure: Header.Payload.Signature (Base64URL encoded, dot-separated)

JWT security concerns:

  • Algorithm confusion: If the server accepts "none" as a signing algorithm, an attacker can forge tokens. Always validate the algorithm in the header against a whitelist.
  • Weak secret: If the HMAC secret is short or guessable, the signature can be brute-forced. Use strong secrets.
  • No built-in revocation: Unlike server-side sessions, a signed JWT cannot be invalidated until it expires. Use short expiry times and implement token revocation lists for high-security use cases.

⚠️ Exam Trap: "Logout ends the session." This is true for server-side sessions — the server deletes the session record. For JWT-based authentication, logout on the client side doesn't invalidate the token — it only removes it from client storage. The token remains valid until expiry. A properly implemented JWT system uses short expiration (minutes) plus refresh tokens (longer-lived, revocable) to balance usability and security.

Reflection Question: A web application stores session tokens in localStorage (accessible to JavaScript) and transmits them via HTTP (not HTTPS). It uses 32-bit sequential session IDs. Identify all three security vulnerabilities, the specific attack each enables, and the correct implementation for each.

Alvin Varughese
Written byAlvin Varughese
Founder15 professional certifications