Knowledge Base

Configure CORS and Cookies

Start with the browser flow you want to permit. Keep cross-origin reading, authentication, and cookie delivery as separate decisions.

Define the required access

If no external web application needs to read the response, do not add CORS merely to satisfy a checklist. For a public resource that needs no credentials, a wildcard origin can be intentional. For a private API, maintain an exact allowlist of scheme, host, and port.

Configure credentialed access

Access-Control-Allow-Origin: https://app.example.com
Access-Control-Allow-Credentials: true
Vary: Origin

This example grants browser reading to one specified origin. If you select the value dynamically, compare against your allowlist first. Merge Origin with any existing Vary fields rather than discarding them.

The client must request credentials, for example with credentials: "include" in fetch. Cookie SameSite settings and browser third-party restrictions can still prevent delivery. An origin allowlist is not user authentication.

Handle preflight and real responses

Answer permitted OPTIONS preflights with the required origins, methods, and request headers. Do not require the preflight itself to carry a session cookie. Authenticate and authorize the actual request, and return the relevant CORS headers on its response, including errors intended to be readable.

Allow only the methods and headers the application needs. Avoid redirecting a preflight to a login page; call the intended HTTPS endpoint directly.

Set cookie boundaries

A same-site authentication flow can often start with Secure; HttpOnly; SameSite=Lax. Cross-site cookie use typically requires SameSite=None; Secure, but browser restrictions still apply. Choose the least broad Domain and Path scope that supports the application, and test incoming login links.

Use CSRF protection for state-changing operations. See cookie attributes, CORS values, and CORS troubleshooting.

Sources

Copyright ©2026 MILAN INNOVATIONS LLC. All rights reserved.