☼
⌃
☰

Session Management Testing

Table of Contents

Session management is the mechanism by which an application maintains state between authenticated requests. Flaws here allow an attacker to hijack, forge, or extend a session without possessing valid credentials. Distinct from Insecure Authentication Mechanism: authentication is the initial proof of identity; session management is everything that happens after.

In SPA architectures the token issued after login is the entire trust boundary. If it can be stolen, forged, fixed, or never invalidated, the authentication step is irrelevant.

Related: Insecure Authentication Mechanism Broken Authentication JWT Attacks Web Application Testing Methodology API Testing Methodology CVSS

1. Cookie Security Flags

Cookies used to carry session tokens must be configured correctly. Each missing flag is a distinct, reportable issue.

Flag Purpose Missing = Risk
HttpOnly Prevents JavaScript from reading the cookie XSS leads to token theft
Secure Cookie only transmitted over HTTPS Token exposed over HTTP intercept
SameSite Controls cross-origin cookie submission CSRF possible if Lax/None
Domain Restricts cookie to specific (sub)domain Token sent to unintended endpoints
Expires Sets token lifetime Session never expires

Testing Cookie Flags

Inspect in Burp Suite → HTTP history → Set-Cookie response header.

SHELL
# Inspect Set-Cookie header via curl
curl -I http://$IP/login -c /dev/null | grep -i "set-cookie"

A secure session cookie looks like this:

Set-Cookie: session=<token>; HttpOnly; Secure; SameSite=Strict; Path=/

Flag each missing attribute as a finding. SameSite=None without Secure is particularly notable — it enables cross-site requests over HTTP.

SameSite Values

Value Behaviour Security implication
Strict Cookie never sent cross-origin Strongest CSRF protection
Lax Sent on top-level navigation GET only Partial CSRF protection
None Always sent cross-origin (requires Secure) CSRF possible — test it

2. Token Storage in SPAs

React SPAs commonly store tokens outside of cookies entirely. Each storage location has a distinct risk profile.

Location Accessible via JS Survives tab close Persists across sessions
localStorage Yes Yes Yes
sessionStorage Yes No No
Memory (state) No No No
HttpOnly cookie No Depends on Expires Yes if Expires set

localStorage and sessionStorage are both accessible via document.cookie — any XSS payload can exfiltrate the token. The presence of a token in either location is a reportable finding under Insecure Authentication Mechanism or Broken Authentication depending on how the exam classifies it.

Testing Token Storage

Open browser DevTools → Application tab.

  • Local Storage: check for token, accessToken, jwt, auth
  • Session Storage: same keys
  • Cookies: note all flags as per section 1
SHELL
# Quick check via curl — look for tokens in JSON response body
# Some SPAs return the token in the response body on login
curl -X POST http://$IP/api/v1/login \
  -H "Content-Type: application/json" \
  -d '{"username":"user","password":"password"}' \
  | python3 -m json.tool

If the token appears in the JSON response body and is stored in localStorage by the frontend, that is the storage pattern to document.

3. Session Fixation

An attacker forces a known session token on the victim before authentication. After the victim logs in, the attacker uses the same pre-known token to access the session.

Prerequisite: the application must accept an externally supplied session token and not rotate it on login.

Test

  1. Obtain a session token without authenticating (e.g. by visiting the application cold — some apps issue a pre-auth session token)
  2. Log in using that token
  3. Check whether the token changes after authentication
SHELL
# Step 1: get pre-auth token
curl -c cookies.txt http://$IP/

# Step 2: log in with the same cookie jar
curl -b cookies.txt -c cookies.txt \
  -X POST http://$IP/login \
  -d "username=user&password=password"

# Step 3: compare the token before and after
# If unchanged, session fixation is possible
cat cookies.txt

If the token is not rotated on login: reportable as session fixation, classified under Broken Authentication or Insecure Authentication Mechanism.

4. Session Expiry and Invalidation

Token Expiry Not Enforced

If the server issues tokens with an exp claim but does not validate it server-side, old tokens remain valid indefinitely. See JWT Attacks — Attack 5 covers this for JWTs specifically.

For non-JWT tokens:

SHELL
# Capture a token, wait for the stated expiry period
# Or simply replay an old token captured from an earlier session
curl -H "Authorization: Bearer $OLD_TOKEN" \
  http://$IP/api/v1/profile

Logout Does Not Invalidate Server-Side

On logout, the client discards the token. If the server does not also invalidate it (i.e. add it to a blocklist or delete from DB), a captured token remains valid after logout.

SHELL
# Step 1: capture token while authenticated
TOKEN=$(curl -s -X POST http://$IP/api/v1/login \
  -H "Content-Type: application/json" \
  -d '{"username":"user","password":"password"}' \
  | python3 -c "import sys,json; print(json.load(sys.stdin)['token'])")

# Step 2: log out via the application

# Step 3: replay the captured token
curl -H "Authorization: Bearer $TOKEN" \
  http://$IP/api/v1/profile

# If this returns 200 with data, server-side invalidation is absent

This is a High severity finding — any captured token (via XSS, network intercept, or access log exposure) grants indefinite access.

5. Reporting Template

Finding: Missing Cookie Security Flags

Severity: Medium (adjust per flag — missing HttpOnly with XSS present escalates to High)

Description: The session cookie is issued without the [HttpOnly / Secure / SameSite] flag. [Describe consequence specific to the missing flag — e.g. the absence of HttpOnly means a cross-site scripting vulnerability on any page in the application can be used to exfiltrate the session token.]

Evidence:

Set-Cookie: session=abc123; Path=/

Remediation: Set the HttpOnly, Secure, and SameSite=Strict attributes on all session cookies. Ensure Secure is set to prevent transmission over unencrypted connections.

—

Finding: Session Token Not Invalidated on Logout

Severity: High

Description: After a user logs out, the session token issued at login remains valid for subsequent API requests. An attacker who obtains a token — via XSS, log exposure, or network interception — retains persistent access regardless of the user logging out.

Evidence: [Include the logout request/response and the subsequent successful API request using the pre-logout token.]

Remediation: Implement server-side token invalidation on logout. For JWT-based systems, maintain a token blocklist or switch to short-lived tokens with server-side session records that can be revoked.

6. CVSS Indicative Scoring

Missing HttpOnly (XSS token theft):

AV:N/AC:H/PR:N/UI:R/S:C/C:H/I:L/A:N
Base Score: 7.1 (High)
Rationale: requires XSS (AC:H), user interaction for XSS trigger

Token not invalidated on logout (indefinite replay):

AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:N
Base Score: 9.1 (Critical)
Rationale: network attacker with captured token has full account access

Session fixation:

AV:N/AC:H/PR:N/UI:R/S:U/C:H/I:H/A:N
Base Score: 7.5 (High)
Rationale: requires victim to be manipulated into using fixed token

Tips

  • In a React SPA, check token storage in DevTools before touching anything else — it tells you the entire session architecture at a glance
  • Missing HttpOnly on its own is Medium; combined with a reflected XSS elsewhere in scope it becomes a High two-step chain — note this in your report
  • Always test logout explicitly: capture the token, log out, replay the token. It takes 30 seconds and is a High finding when it fails
  • Session fixation is less common in JWT architectures (tokens are stateless) but still possible with cookie-based session tokens
  • On the exam, document cookie flags as individual findings if multiple are missing — each is a separate issue with a separate remediation