Authentication and API security

Layer CSRF protections for cookie-authenticated requests

Use SameSite cookies, anti-CSRF tokens and Origin validation according to the application's cross-site request requirements. Browsers attach cookies automatically, which can let a third-party site trigger state changes. SameSite is useful but does not protect every flow or older client configuration. Security controls depend on client type, data sensitivity and deployment context; verify provider and standards guidance before production changes.

Threat model and trust boundaries

Browsers attach cookies automatically, which can let a third-party site trigger state changes. SameSite is useful but does not protect every flow or older client configuration.

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

Implementation approach

Use secure HttpOnly cookies with an intentional SameSite value, require anti-CSRF tokens for state-changing requests where needed, validate Origin or Referer as defense in depth, and never mutate state through GET.

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

Practical example

A bank-transfer endpoint requires a session-bound CSRF token and verifies the expected Origin; the application does not rely only on a hidden form field supplied by the client.

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

Verification and follow-up

Test cross-site form submissions, same-site subdomains, missing tokens, invalid origins and legitimate OAuth callbacks; review cookie behavior in supported browsers.

  • 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?

Use SameSite cookies, anti-CSRF tokens and Origin validation according to the application's cross-site request requirements.

What should be checked before rollout?

Test cross-site form submissions, same-site subdomains, missing tokens, invalid origins and legitimate OAuth callbacks; review cookie behavior in supported browsers.