Session Security

CWE-384, CWE-613, CWE-620, CWE-304, CWE-306

Real-World Attack Scenarios

Scenario 1: Session Fixation

Attacker sets victim's session ID to a known value:

Attacker obtains session ID: abc123def456
Sends victim URL with this SID: http://example.com/?sid=abc123def456
Victim clicks link, uses attacker's SID
Attacker uses same SID: cookie: sessionid=abc123def456
Both user and attacker have same session!
Attacker can see what victim sees, perform actions as victim

The attack:

# Attacker sets own session
curl http://example.com -c cookies.txt
# Receives: Set-Cookie: sessionid=abc123def456

# Attacker sends victim this link
http://example.com/?sid=abc123def456

# Victim clicks, uses attacker's session
# Victim logs in with this session
# Now attacker is logged in as victim!

# Attacker uses same sessionid
curl http://example.com/account -b "sessionid=abc123def456"
# Victim's account!

Result:

  • Account takeover without credentials

  • No password needed

  • Attacker access to victim's account

Finding it: Try setting session ID. Check if server accepts attacker-supplied SID.


Scenario 2: Insufficient Session Expiration

Session valid for too long (1 year expiration):

The attack:

Result:

  • Extended compromise window

  • Stolen sessions valid longer

  • Increased risk

Finding it: Check session expiration. Try using old session IDs. Verify logout clears session.


Scenario 3: Unverified Password Change

Password can be changed without verifying old password:

The attack:

Attacker accesses victim's session (XSS, CSRF, session theft):

Result:

  • Account takeover

  • Victim locked out

  • No verification required

Finding it: Test password change without old password verification. Use session hijacking + password change.


Scenario 4: Missing Authentication Step

Critical operation skips authentication check:

The attack:

Result:

  • Delete any account

  • Denial of service

  • Data destruction


Scenario 5: Insufficient Multi-Factor Authentication

2FA implemented but with weaknesses:

The attack:

User without MFA set up:

Or with weak MFA:

Result:

  • Complete account compromise

  • MFA bypass

Finding it: Test with credentials + no MFA. Try MFA bypass. Intercept SMS codes.


Mitigation Strategies

Regenerate session ID on login

Set appropriate session expiration

Require password verification for sensitive changes

Require authentication for all critical operations

Implement proper 2FA

  • Use TOTP (time-based, not SMS)

  • Backup codes for recovery

  • Rate limiting on attempts

  • Code expiration

  • No 2FA bypass

Invalidate sessions on logout


Last updated