Authentication and API security

Configure CORS origins and credentials deliberately

Set cross-origin resource-sharing rules that allow only required origins and do not combine credentials with wildcard origins. CORS is a browser response-sharing policy, not authentication. Reflecting arbitrary Origin values while allowing credentials can expose authenticated responses to hostile sites. Security controls depend on client type, data sensitivity and deployment context; verify provider and standards guidance before production changes.

Threat model and trust boundaries

CORS is a browser response-sharing policy, not authentication. Reflecting arbitrary Origin values while allowing credentials can expose authenticated responses to hostile sites.

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

Implementation approach

Maintain an explicit origin allowlist, vary cached responses by Origin when reflecting it, restrict methods and headers, and pair credentialed requests with appropriate cookie and CSRF controls.

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

Practical example

An API accepts https://console.example and rejects https://console.example.attacker.test; authenticated responses never use Access-Control-Allow-Origin: *.

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

Verification and follow-up

Test allowed and denied origins, preflight methods, credential behavior and cache variation; confirm server authorization still applies to non-browser requests.

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

Set cross-origin resource-sharing rules that allow only required origins and do not combine credentials with wildcard origins.

What should be checked before rollout?

Test allowed and denied origins, preflight methods, credential behavior and cache variation; confirm server authorization still applies to non-browser requests.