Skip to content
Pro Analyzer — Available with ShieldCI Pro

Session Timeout Analyzer

Analyzer IDCategorySeverityTime To Fix
session-timeout🛡️ SecurityMedium5 minutes

What This Checks

This analyzer validates session timeout, cookie security, and lifetime configuration across your Laravel application:

  • Session lifetime - Checks config/session.php for lifetime values exceeding 120 minutes (2 hours). Supports both direct values and env() defaults
  • Expire on close - Recognizes expire_on_close => true as a mitigating factor; downgrades excessive lifetime issues to Low severity rather than suppressing them, as browser behavior varies
  • Remember me tokens - Checks config/auth.php for custom remember token lifetime keys exceeding 30 days
  • Cookie secure flag - Flags secure => false; High severity. Cookie sent over unencrypted HTTP in production
  • Cookie HttpOnly flag - Flags http_only => false; Medium severity. JavaScript can read the session cookie (XSS risk)
  • Cookie SameSite attribute - Flags same_site => 'none' without secure => true (browser-rejected); High severity. Flags same_site => 'none' alone (cross-origin exposure); Medium severity
  • Session driver - Flags driver => 'cookie' (client-side session storage); Medium severity

Recommended limits:

ContextMaximum Lifetime
General applications120 minutes (2 hours)
Sensitive/financial apps15 minutes
Admin panels30 minutes
Remember me tokens30 days

Why It Matters

Excessively long session lifetimes increase the window for several attack vectors:

  • Session hijacking - Longer sessions give attackers more time to steal or use a captured session ID
  • Session fixation - Extended sessions increase exposure to fixation attacks
  • Unattended device access - If a user leaves a device unlocked, long sessions allow unauthorized access
  • Compliance violations - PCI-DSS, HIPAA, and similar standards require session timeout enforcement
  • Stale authentication - Users who change passwords or have accounts disabled remain logged in

How to Fix

Quick Fix (2 minutes)

Update session lifetime in config/session.php:

Before (❌):

php
// config/session.php
return [
    // 24 hours - excessively long
    'lifetime' => env('SESSION_LIFETIME', 1440),

    'expire_on_close' => false,
];

After (✅):

php
// config/session.php
return [
    // 2 hours - appropriate for general applications
    'lifetime' => env('SESSION_LIFETIME', 120),

    'expire_on_close' => false,
];

Proper Fix (5 minutes)

Configure appropriate session lifetime and cookie security:

Session configuration:

php
// config/session.php
return [
    // General app: 120 minutes, Sensitive app: 15 minutes
    'lifetime' => env('SESSION_LIFETIME', 120),

    'expire_on_close' => false,

    // Cookie security
    'secure' => env('SESSION_SECURE_COOKIE', true),
    'http_only' => true,
    'same_site' => 'lax',
];

Environment-specific session lifetime:

ini
# .env (production - general app)
SESSION_LIFETIME=120

# .env (production - financial app)
SESSION_LIFETIME=15

# .env (local development)
SESSION_LIFETIME=480

Sanctum and Passport token expiration

Sanctum and Passport token lifetimes are validated by their dedicated analyzers: Sanctum Security and Passport Security.

References