Authentication and API security

Set secure cookie attributes and session lifetimes

Configure cookie scope, transport, script access and expiry to match a documented authentication lifecycle. Broad Domain scope, missing Secure or overly long-lived cookies increase exposure. HttpOnly limits JavaScript access but does not prevent CSRF or session theft from a compromised device. Security controls depend on client type, data sensitivity and deployment context; verify provider and standards guidance before production changes.

Threat model and trust boundaries

Broad Domain scope, missing Secure or overly long-lived cookies increase exposure. HttpOnly limits JavaScript access but does not prevent CSRF or session theft from a compromised device.

  • Identify actors, assets and trust boundaries
  • Choose controls that address the stated threat
  • Test failure behavior and recovery paths

Implementation approach

Use Secure on HTTPS, HttpOnly for session identifiers, a deliberate SameSite policy and the narrowest practical Path/Domain. Rotate identifiers after authentication or privilege changes and invalidate sessions on logout.

  • Confirm the responsible owner
  • Apply the change to a representative case
  • Document decisions and exceptions

Practical example

An application replaces its anonymous session ID after login and uses a host-only Secure, HttpOnly cookie with a reviewed SameSite setting.

  • Reproduce the starting situation
  • Apply the described approach
  • Check the user-facing result

Verification and follow-up

Inspect cookies in supported browsers, test login fixation and logout invalidation, and verify session expiry and account-recovery behavior.

  • Test expected and failure cases
  • Compare with the recorded baseline
  • Agree the next review date and owner

Questions to keep in view

When should a team use this authentication and api security guide?

Configure cookie scope, transport, script access and expiry to match a documented authentication lifecycle.

What should be checked before rollout?

Inspect cookies in supported browsers, test login fixation and logout invalidation, and verify session expiry and account-recovery behavior.