Authentication and API security

Bind OAuth state to prevent callback CSRF

Generate, store and validate OAuth state values to bind authorization callbacks to the initiating browser session. A callback can be induced through a victim's browser. A random state value stored only in an attacker-controlled request does not help unless the application checks it against the session that started authorization. Security controls depend on client type, data sensitivity and deployment context; verify provider and standards guidance before production changes.

Threat model and trust boundaries

A callback can be induced through a victim's browser. A random state value stored only in an attacker-controlled request does not help unless the application checks it against the session that started authorization.

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

Implementation approach

Create a high-entropy state value, associate it with the initiating session and expected provider, expire it promptly, and reject missing, reused or mismatched values before processing the callback.

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

Practical example

Two browser sessions start login at the same time; each callback is accepted only by the session holding its matching one-time state value.

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

Verification and follow-up

Test cross-session callback swaps, duplicate callback replay, login cancellation and expired state. Avoid placing personal data or secrets directly in state.

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

Generate, store and validate OAuth state values to bind authorization callbacks to the initiating browser session.

What should be checked before rollout?

Test cross-session callback swaps, duplicate callback replay, login cancellation and expired state. Avoid placing personal data or secrets directly in state.