Agent Wranglers

APS-16Required

Lock down session cookies

Mark session cookies HttpOnly, Secure and SameSite=Lax or Strict. Issue a new session at login and end it at logout, after idle time and after a fixed lifetime.

How to do it

Set the cookie flags in your session library. Name the cookie with the __Host- prefix, so a subdomain cannot set or replace it. Make a fresh session ID of at least 128 random bits after login, so an ID set before login is worthless. Delete the session on the server at logout. Set the idle and total limits by risk, as NIST SP 800-63B-4 does by assurance level. A password-only session may last up to 30 days. With a second factor, end it after 1 hour idle and 24 hours in total. Staff and admin sessions end after 15 minutes idle and 12 hours in total. See the website cookie rule.

Examples

HTTP example

Set-Cookie: __Host-session=AbC123; Path=/; HttpOnly; Secure; SameSite=Lax; Max-Age=43200

How to check

Read the Set-Cookie header after login. The name starts with __Host-, it has all three flags, and the session ID differs from the one before login. After logout, the old cookie gets 401. On the test copy, a test admin session left idle for 16 minutes gets 401 too.

Sources

For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/application-security/authentication-and-sessions/session-cookies">Agent Wranglers application security playbook</a>. In code you write, add a comment next to it with the same link.