Reference

Security & identity

Look up identity, access checks, browser defenses, secrets and safe input boundaries.

Scope and conventions

Web/API security patterns, not a complete authentication implementation or security certification. Sequences are labeled sketches. Use maintained framework/provider libraries for identity and cryptography; adapt policies to your trust boundaries. Primary sources accompany each entry.

Sessions & tokens

Carry an opaque session ID in a protected cookie

Web & API security

A server-side session maps an unpredictable identifier to server-owned state. Secure limits cookie transport to secure channels; HttpOnly prevents script reads, and SameSite controls cross-site sending. The server still owns expiry, revocation and authorization.

Fragment

Illustrative Set-Cookie response header. Generate the value through your session library; __Host- cookies must omit Domain.

Web & API security · Carry an opaque session ID in a protected cookie
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
Set-Cookie: __Host-session=OPAQUE_VALUE; Path=/; Secure; HttpOnly; SameSite=Lax

Rotate, expire and invalidate sessions server-side

Web & API security

Regenerate the session identifier after login or privilege changes and invalidate the old identifier. Enforce idle/absolute expiry on the server; logout must invalidate server-side authority, not just remove a browser cookie.

Protocol / decision sketch

Sequence or decision sketch; not executable code.

Web & API security · Rotate, expire and invalidate sessions server-side
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
anonymous ID → login → new authenticated ID
old ID       → invalid
logout       → invalidate session + expire browser cookie

Verify a JWT before trusting its claims

Web & API security

Decoding a JWT only reads data. A maintained verifier must enforce an explicit algorithm policy, signature/key trust, expected issuer and audience, time validity and the intended token type. Signed JWT payloads are generally readable.

Protocol / decision sketch

Sequence or decision sketch; not executable code.

Web & API security · Verify a JWT before trusting its claims
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
untrusted compact token
→ verify signature and configured algorithm/key
→ validate issuer, audience, time and token purpose
→ apply application authorization

Choose token lifetime and revocation behavior

Web & API security

A valid signed token may remain acceptable until expiry unless the application checks additional revocation/session state. Token storage and refresh rotation must match the client and threat model; a JWT does not automatically implement logout.

Protocol / decision sketch

Sequence or decision sketch; not executable code.

Web & API security · Choose token lifetime and revocation behavior
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
short-lived access token + defined refresh/revocation policy
server-side session    + server-side invalidation policy