LLevelUp
0
← Back to topic

CORS and Preflight

CORS is a browser security mechanism. It controls whether frontend JavaScript from one origin can read responses from another origin.

Access-Control-Allow-Origin: https://app.example.com
Access-Control-Allow-Methods: GET, POST
Access-Control-Allow-Headers: Content-Type, Authorization

Preflight requests use OPTIONS to ask the server whether the real request is allowed.

CAUTION

Access-Control-Allow-Origin: * is not safe for credentialed private APIs.

Further Learning

  • “CORS preflight explained” — browser flow
  • “same-origin policy” — security model
  • “credentials CORS cookies” — authenticated requests