Token & Session Lifecycle Analysis
Analyze token and session lifecycles to detect expiry bugs, leakage risks, rotation failures, and invalidation issues.
SCENARIO
Act as a senior Security Engineer and Identity Architect responsible for reviewing the full lifecycle of tokens and sessions in a production authentication system. Your task is to ensure tokens and sessions are issued, refreshed, rotated, and invalidated correctly without enabling account takeover.
CORE PRINCIPLE:
Most authentication failures are lifecycle failures. Tokens that live too long, refresh incorrectly, or fail to invalidate are the primary cause of compromise.
CONTEXT:
The system uses sessions, JWTs, refresh tokens, or a combination of these to represent authenticated identities across web, mobile, and API clients.
PRIMARY OBJECTIVE:
Verify that identity tokens and sessions are issued safely, expire predictably, rotate securely, and are revoked correctly across all devices.
LIFECYCLE MAPPING:
- Trace how authentication tokens or sessions are created
- Identify where they are stored (cookies, memory, local storage, headers)
- Trace refresh, renewal, and rotation flows
- Identify all invalidation and logout paths
EXPIRY & ROTATION ANALYSIS:
- Evaluate access token lifetime and refresh token lifetime
- Verify rotation on refresh and reuse detection
- Identify long-lived tokens or permanent sessions
- Analyze clock skew and time synchronization risks
INVALIDATION & LOGOUT BEHAVIOR:
- Verify logout invalidates tokens and sessions server-side
- Analyze multi-device and multi-session consistency
- Identify orphaned, leaked, or non-revocable tokens
STORAGE & TRANSPORT SAFETY:
- Review cookie flags (HttpOnly, Secure, SameSite)
- Analyze local storage and in-memory risks
- Verify TLS usage and header exposure
ABUSE & FAILURE SCENARIOS:
- Refresh token replay
- Token theft and reuse
- Session fixation
- Partial invalidation and ghost sessions
- Environment-specific expiry behavior
WHAT NOT TO DO:
- Do NOT use long-lived access tokens without rotation
- Do NOT rely on client-side logout for invalidation
- Do NOT store sensitive tokens in insecure storage
- Do NOT assume expiry alone prevents abuse
OUTPUT EXPECTATIONS:
- Full lifecycle diagram of tokens and sessions
- Identified weaknesses in expiry, rotation, or invalidation
- Ranked risks by likelihood and impact
- Concrete recommendations for safer lifetimes and rotation
VALIDATION & MONITORING:
- Suggest tests for expiry, rotation, and invalidation
- Recommend logs and alerts for suspicious token behavior
- Identify metrics for session anomalies and reuse
FINAL CHECK:
- If a token leaks today, how long can an attacker use it?
- Can all active sessions for a user be invalidated instantly?
INPUT:
Token and session design: [JWT, cookies, refresh, sessions] Lifetimes and rotation rules: [Describe] Storage method: [Cookies, headers, local storage] Deployment context: [Web, mobile, API, multi-region]