---
title: "Authentication and sessions · Agent Wranglers"
url: https://agentwranglers.se/playbook/application-security/authentication-and-sessions
parts: 10
tokens_total: 10061
updated: 2026-10-27
build: a2a6bdfed830
tokens: 1315
licence: "CC BY 4.0"
licence_url: https://creativecommons.org/licenses/by/4.0/
---

# Authentication and sessions

For AI agents: the [site map](https://agentwranglers.se/llms.txt) lists everything here, and this page sits under [Application security](https://agentwranglers.se/playbook/application-security.md).

By [Agent Wranglers](https://agentwranglers.se/authors/agent-wranglers.md). Updated 2026-10-27.

> Slow down guessing, store passwords safely, verify every token and keep session cookies locked to your own site and to the signed-in person.

These rules cover the security mechanics of signing in. How people sign up, which sign-in methods to offer, second factors, recovery and business sign-on live in the [Accounts and identity playbook](https://agentwranglers.se/playbook/accounts.md). SAML and OpenID Connect checks for business sign-on are in [Connect single sign-on per organisation](https://agentwranglers.se/playbook/accounts/business-sign-on-and-provisioning/organisation-sso.md).

**For agents:** this playbook is free to use under [CC BY 4.0](https://creativecommons.org/licenses/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">Agent Wranglers application security playbook</a>`. In code you write, add a comment next to it with the same link.

## Required

- APS-10 [Slow down password guessing](https://agentwranglers.se/playbook/application-security/authentication-and-sessions/login-guessing.md) · 874 tokens · updated 2026-10-27
  Limit failed logins per account and per client address. Give the same error for a wrong user and a wrong password.
- APS-11 [Store passwords with a slow hash](https://agentwranglers.se/playbook/application-security/authentication-and-sessions/password-storage.md) · 1,040 tokens · updated 2026-10-27
  Store passwords only as a slow, salted hash made for passwords, such as Argon2id or bcrypt.
- APS-12 [Verify every token](https://agentwranglers.se/playbook/application-security/authentication-and-sessions/token-checks.md) · 1,322 tokens · updated 2026-10-27
  Check the signature, algorithm, expiry and audience of every signed token, such as a JWT. Give access tokens a life of 15 minutes or less. This is the one home of that limit.
- APS-15 [Trust an email domain only after strict parsing](https://agentwranglers.se/playbook/application-security/authentication-and-sessions/strict-email-parsing.md) · 1,088 tokens · updated 2026-10-27
  Before an email domain grants anything, such as joining an organisation or routing single sign-on, check the address against one plain `local@domain` shape. Refuse quotes, comments, encoded words, `%` and more than one `@`.
- APS-16 [Lock down session cookies](https://agentwranglers.se/playbook/application-security/authentication-and-sessions/session-cookies.md) · 1,186 tokens · updated 2026-10-27
  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.
- APS-17 [Set cookies safely or not at all](https://agentwranglers.se/playbook/application-security/authentication-and-sessions/cookie-attributes.md) · 856 tokens · updated 2026-10-27
  Set every cookie with `Secure` and an explicit `SameSite`. Add `HttpOnly` to every cookie that no script reads. Use `SameSite=None` only for a cookie that must work inside another site.
- APS-18 [Block cross-site form posts](https://agentwranglers.se/playbook/application-security/authentication-and-sessions/cross-site-requests.md) · 1,058 tokens · updated 2026-10-27
  Make sure a change of state only comes from your own pages, with `SameSite` cookies plus a token or an origin check.
- APS-19 [Clear cached pages and data when someone signs out](https://agentwranglers.se/playbook/application-security/authentication-and-sessions/clear-site-data-on-sign-out.md) · 996 tokens · updated 2026-10-27
  On sign-out, delete everything the browser stored for the account. That covers the service worker's caches, local storage and cookies.

## Recommended

- APS-13 [Compare secrets in constant time](https://agentwranglers.se/playbook/application-security/authentication-and-sessions/constant-time-compare.md) · 666 tokens · updated 2026-10-27
  Compare tokens, signatures and codes with a constant-time function, so response times reveal nothing about how close a guess was.
- APS-14 [Make tokens from a secure random source](https://agentwranglers.se/playbook/application-security/authentication-and-sessions/secure-random-tokens.md) · 975 tokens · updated 2026-10-27
  Make session IDs, reset codes, API keys and invite links only with the platform's cryptographic random generator. Never use the plain random function, a timestamp or a counter.

## Read this with

- [Accounts and identity playbook](https://agentwranglers.se/playbook/accounts.md). Password hashing, token checks and session cookies are the security mechanics under every sign-in.

- Previous: [Input and injection](https://agentwranglers.se/playbook/application-security/input-and-injection.md)
- Next: [Access control](https://agentwranglers.se/playbook/application-security/access-control.md)
- [All chapters](https://agentwranglers.se/playbook/application-security.md)
