Skip to content

CORS preflight checker

Check whether a cross-origin request from your page will pass CORS, from its method and headers and the server’s response headers.

Runs in your browser. Nothing you paste is sent to us.

The request

Where the JavaScript runs.

One per line, as Name: value.

Sample values are filled in. Paste the preflight response, for example from your browser’s network panel.

Result

Passes CORS Preflight needed

A preflight OPTIONS request is sent first, because the header authorization is not on the safe list.
Access-Control-Allow-Origin matches https://app.example.com.
Access-Control-Allow-Headers includes authorization.
Browsers may cache this preflight for up to 3600 seconds (Chrome caps it at 7200).
The actual response needs the same Access-Control-Allow-Origin (and Allow-Credentials) as the preflight.
Worked out from the rules browsers follow (the Fetch standard). Nothing is sent to the URL.

How to use it

  1. Enter the page’s origin and the URL it calls.
  2. Choose the method and add the headers your code sets.
  3. Tick credentials if the request sends cookies.
  4. Paste the server’s response headers and read the result.

What to know

CORS lets a server say which other origins may read its responses. For requests that are not simple, such as ones with an Authorization header or a JSON body, the browser first sends an OPTIONS preflight.

The checks follow the Fetch standard: an exact origin match, no wildcard with credentials, and an Authorization header that must be listed by name.

In Keycloak, a client’s Web origins setting decides which origins get CORS headers on endpoints such as token and userinfo. A + allows the origins of the client’s valid redirect URIs.

What CORS is and why browsers enforce it

Browsers follow the same-origin policy: a script on https://app.example.com may send requests to another origin, but it may not read the responses unless that origin agrees. An origin is the scheme, host and port together, so https://auth.example.com and https://app.example.com are different origins.

Cross-Origin Resource Sharing (CORS) is how a server agrees. It sends Access-Control-Allow-* headers that name which origins may read its responses, with which methods and headers, and whether cookies may come along. The rules live in the WHATWG Fetch standard.

CORS is enforced by browsers only. It protects users from malicious pages reading data with the user’s cookies; it does not stop servers, scripts or tools outside a browser from calling an API.

Simple requests and preflight requests

Some requests could already be made by an ordinary HTML form, so browsers send them straight away and only check the response. Everything else triggers a preflight: an OPTIONS request that asks the server for permission first.

Sent without preflight when…Otherwise a preflight is needed
Method is GET, HEAD or POSTPUT, PATCH, DELETE or any other method
Headers are only Accept, Accept-Language, Content-Language, Content-Type or a simple RangeAny other header, such as Authorization or X-Requested-With
Content-Type is application/x-www-form-urlencoded, multipart/form-data or text/plainapplication/json or any other type
A preflight and a passing response (sample values)
OPTIONS /realms/acme/protocol/openid-connect/userinfo HTTP/1.1
Origin: https://app.example.com
Access-Control-Request-Method: GET
Access-Control-Request-Headers: authorization

HTTP/1.1 200 OK
Access-Control-Allow-Origin: https://app.example.com
Access-Control-Allow-Methods: GET, POST, OPTIONS
Access-Control-Allow-Headers: Authorization, Content-Type
Access-Control-Max-Age: 3600
Vary: Origin

The rules the browser applies

The checker applies the same rules, in the same order, as a browser does.

Access-Control-Allow-Origin

It must be exactly the request’s origin, or *. Exactly means character for character: no trailing slash, no path, lowercase scheme and host, and only one value. A list of origins in this header is invalid; the server has to pick the matching one and echo it.

Credentials

When the request includes credentials (cookies or HTTP authentication, as with credentials: 'include' in fetch), the response must send Access-Control-Allow-Credentials: true, and every allow header must name things explicitly. * is not allowed in that case, neither for the origin, the methods nor the headers.

Methods and headers

The preflight response must list the method in Access-Control-Allow-Methods unless it is a simple method, and every non-simple request header in Access-Control-Allow-Headers. Header names compare without regard to case. A * wildcard for headers never covers Authorization; it must always be listed by name.

Status and caching

The preflight must answer with a 2xx status. A preflight that hits authentication and returns 401 fails, because preflights never carry credentials. Access-Control-Max-Age lets the browser reuse a preflight result; Chrome caps it at two hours.

What this checker does and does not do

  • It decides whether a request needs a preflight, and says why.
  • It checks the response headers you paste against the Fetch standard’s rules for origin, credentials, methods and headers, including the special case for Authorization.
  • It notes headers browsers do not let scripts set, the 2xx rule for preflights, preflight caching and the need for Vary: Origin.
  • It treats the pasted headers as the preflight response and the actual response together. In real traffic both must pass.
  • It sends nothing to the URL you enter. To see what a server really returns, capture the response in your browser’s network panel and paste it.

How to check a request

  1. Enter the origin of the page whose JavaScript makes the call.
  2. Enter the URL it calls and choose the method.
  3. List the headers your code sets, one per line, such as Authorization: Bearer … or Content-Type: application/json.
  4. Tick credentials if the request sends cookies.
  5. Paste the server’s response headers, ideally from the failing preflight in the network panel.
  6. Read the verdict and the step that fails.

CORS with Keycloak

Single-page apps talk to Keycloak from the browser: they exchange the authorization code at the token endpoint, refresh tokens and sometimes call userinfo. Those calls are cross-origin whenever Keycloak and the app have different origins, so CORS has to be right.

Web origins

Keycloak decides which origins receive CORS headers from each client’s Web origins setting. List the app’s origins, such as https://app.example.com, without paths or trailing slashes. + means "the origins of this client’s valid redirect URIs", which is usually what a single-page app needs. * allows every origin and should be avoided.

Allowed origins in tokens

Keycloak also puts the client’s web origins in access tokens as the allowed-origins claim. Some resource servers read it to decide CORS for their own APIs, so the same list governs both.

Admin REST API from a browser

Calling Keycloak’s admin REST API from browser code is cross-origin too, and the client used for it needs web origins set in the same way.

Common CORS errors and fixes

Error in the consoleCauseFix
No Access-Control-Allow-Origin header is presentThe server sent no CORS headers for this originAdd the origin to the allow list, in Keycloak to the client’s web origins
The value of Access-Control-Allow-Origin must not be the wildcard * when credentials mode is include* with cookiesEcho the exact origin and send Allow-Credentials: true
Request header field authorization is not allowedAuthorization missing from Allow-HeadersList Authorization by name
Response to preflight request does not have HTTP ok statusThe OPTIONS request got 401, 404 or a redirectLet OPTIONS through without authentication and answer 2xx
Origin does not matchTrailing slash, wrong scheme or portCompare the exact origin string

Security notes

  • Never reflect any origin that asks while also allowing credentials. That lets every website read your users’ data with their cookies.
  • Avoid * for authenticated APIs, and avoid pattern matches on origins that an attacker could satisfy, such as "ends with example.com", which evil-example.com also does.
  • Remember that simple requests still reach the server. CORS stops the page from reading the response, not the request from being processed. State-changing endpoints need CSRF protection or non-simple requests.
  • Send Vary: Origin whenever the allowed origin depends on the request, so caches do not serve one origin’s response to another.

Best practices

  • Keep an explicit list of allowed origins per environment.
  • Prefer bearer tokens in the Authorization header over cookies for cross-origin APIs; then credentials mode is not needed.
  • Answer preflights quickly and without authentication.
  • Set a reasonable Access-Control-Max-Age to save round trips.
  • Where possible, serve the app and its API from the same origin, behind one proxy, and avoid CORS entirely.

Debugging CORS step by step

The browser console names the failing rule, but not always clearly. Working through the request in order finds most problems quickly.

  1. In the network panel, find the failing request. If there is an OPTIONS request just before it, the preflight is where to look first.
  2. Check the preflight’s status. Anything other than 2xx fails, including redirects.
  3. Copy the preflight’s response headers and the request’s Origin, method and headers into this checker.
  4. If the preflight passes, check the actual response: it needs Access-Control-Allow-Origin too, and Allow-Credentials when cookies are sent.
  5. Change one thing on the server, reload with the cache disabled, and check again; cached preflights can hide a fix for up to their max age.
Questions

Frequently asked questions

What causes "No Access-Control-Allow-Origin header is present"?

The server did not send CORS headers for your page’s origin. Add the origin to the server’s allow list; for Keycloak endpoints, add it to the client’s Web origins.

Can I use Access-Control-Allow-Origin: * with cookies?

No. With credentials the browser requires the exact origin in Access-Control-Allow-Origin and Access-Control-Allow-Credentials: true.

Why does my request send an OPTIONS request first?

It is a preflight. The browser sends one when the method is not GET, HEAD or POST, or when the request has headers such as Authorization or a JSON content type.

Does Access-Control-Allow-Headers: * cover Authorization?

No. The Fetch standard excludes Authorization from the wildcard, so it must be listed by name. The wildcard also does not apply to requests with credentials.

Can I list several origins in Access-Control-Allow-Origin?

No. The header holds one origin or *. A server that serves several origins checks the request’s Origin against its list and echoes the matching one, with Vary: Origin.

Does CORS protect my API from attackers?

Not on its own. It stops other websites from reading responses in a user’s browser. Attackers can still call your API directly, so it needs authentication and authorization.

What does + mean in Keycloak web origins?

It allows the origins of all the client’s valid redirect URIs, so you do not have to list them twice. It is the usual setting for single-page apps.

Why does the preflight fail with 401?

Preflight requests never carry credentials, so an endpoint that demands authentication for OPTIONS rejects them. Allow OPTIONS without authentication and answer with a 2xx status.

Rather not run Keycloak yourself?

We run it for you on a cluster of your own, with backups, upgrades and written support. Starter and Premium begin with a 7-day trial.