Keycloak CORS: the Web Origins Setting That Fixes It

Guilliano MolaireGuilliano MolaireUpdated 10 min read

The Web origins setting on your Keycloak client “handles Cross-Origin Resource Sharing (CORS)” (Keycloak Server Administration Guide), so the fix for a Keycloak CORS error is to add your app’s exact origin there (scheme, host and port, with no path and no trailing slash), or to use + to derive the origins from Valid redirect URIs, and never to use * in production. A CORS error on your own API is not a Keycloak setting, and you fix it on that server.

CORS (Cross-Origin Resource Sharing) is “an HTTP-header based mechanism that allows a server to indicate any origins (domain, scheme, or port) other than its own from which a browser should permit loading resources” (MDN, CORS). Your app at https://myapp.com and Keycloak at https://auth.example.com are different origins, so the browser needs Keycloak’s permission before your JavaScript can read a token response.

This post is how to configure Web origins correctly. If you need the diagnostic path instead, including CORS on your own API, go to Keycloak CORS error troubleshooting.

How to set Web origins in the Keycloak 26 admin console

The field is on the client, not on the realm or the server, and the steps are the same whether you use keycloak-js or another OIDC library:

  1. In the admin console, select your realm and open Clients.
  2. Select the client whose client_id your app sends.
  3. On the Settings tab, go to the Access settings section and find Web origins.
  4. Add the origin from the browser error, then click Save.

If you cannot find the field, check that Standard flow is on in the client’s capability config, which is worth doing anyway because a browser login with the authorization code flow needs it.

An entry has to be the origin itself, which is the scheme, the host and any non-default port:

https://myapp.com
https://app.example.com:8443
http://localhost:3000

These entries look close but never match a browser’s Origin header:

https://myapp.com/        # trailing slash
https://myapp.com/app     # has a path
https://*.myapp.com       # no wildcard subdomains

They fail because the Origin header a browser sends holds only the scheme, hostname and port, so an entry with a path or a trailing slash cannot equal it. Keycloak’s documentation also does not describe wildcard subdomains for this field, and the admin console’s help text, quoted in the next section, names only + and * as special values, so list each origin as its own entry. For a new SPA client, our guide to creating a PKCE authorization flow client covers the other settings, and the JavaScript and React integration docs cover the app side.

What + and * mean in Web origins

The admin console’s help text sums up both values: “Allowed CORS origins. To permit all origins of Valid Redirect URIs, add ‘+’. This does not include the ‘’ wildcard though. To permit all origins, explicitly add ‘’.” (Keycloak admin console messages).

Value What Keycloak does Use it for
https://myapp.com Allows exactly that origin Any client, and the clearest choice in production
+ Adds the origin of each http or https Valid redirect URI Keeping the two lists in sync
* Allows every origin Short local experiments, never production

With +, a redirect URI of https://myapp.com/* gives the origin https://myapp.com. In the 26.8.1 source, Keycloak builds that origin by cutting the URI at the first slash after the host, so a wildcard in the host or port of a redirect URI, such as http://localhost:*/*, becomes the text http://localhost:*, which no browser will ever send. List those origins explicitly. A broad redirect URI also widens CORS when you use +, so keep that list tight, and see redirect URI mismatch troubleshooting if logins fail after you tighten it.

The * value permits every origin, as that help text says, so a script on any website can pass the CORS check for that client. The Keycloak docs ask for the opposite when they say to configure Valid Redirect URIs and Web Origins, and add: “Be as specific as possible as failing to do so may result in a security vulnerability” (Keycloak JavaScript adapter).

Which Keycloak requests Web origins controls

Web origins applies to the calls your JavaScript makes with fetch or XMLHttpRequest, and the two you will meet most are the token endpoint and the userinfo endpoint. Keycloak checks the token request against the client that the request names, and the userinfo request against the client the access token was issued to.

How Keycloak checks Web origins: the login redirect is not subject to CORS, the token POST is, and only a matching Origin gets the header the browser needs

The login redirect is a page navigation, so CORS does not apply (1). Your app then sends the token POST with an Origin header (2), and Keycloak compares it with the client’s Web origins (3). On a match the response carries the header and your code reads the tokens (4), and otherwise the header is missing and the browser reports a CORS error (5).

No ‘Access-Control-Allow-Origin’ header is present on the requested resource

This is the error you will see most often, and the full message looks like this:

Access to fetch at 'https://auth.example.com/realms/myrealm/protocol/openid-connect/token'
from origin 'https://myapp.com' has been blocked by CORS policy:
No 'Access-Control-Allow-Origin' header is present on the requested resource.

Cause: the origin in the message is not in the Web origins of the client your app names, or your app is sending a different client_id than the one you edited.

Fix: copy the origin from the message into Web origins exactly as written, then check the client_id on the blocked request in the Network tab. The Keycloak upgrading guide, in its notes for 26.6.3, says that cross-origin requests to endpoints such as token and userinfo are now checked against the client’s Web Origins first, and that a request that does not match is “rejected immediately with a CORS failure returning Forbidden (403) HTTP error status”. A 403 on the token or userinfo request can therefore be this same Web origins problem.

If the blocked URL is under your own API’s domain, Keycloak is not involved, and the section on your own API below applies.

Response to preflight request doesn’t pass access control check

A preflight is the OPTIONS request a browser sends before a request that is not “simple”, for example one with an Authorization header, because only a short list of headers is safelisted (MDN, CORS). The Fetch Standard defines the full protocol.

Access to fetch at 'https://auth.example.com/realms/myrealm/protocol/openid-connect/userinfo'
from origin 'https://myapp.com' has been blocked by CORS policy:
Response to preflight request doesn't pass access control check.

Cause: a failing preflight does not always point at Web origins, so look at the response before you edit the client. It can mean that something else answered it, such as a proxy returning its own OPTIONS response, or a wrong URL returning a 404, as old paths under /auth/ do on a current server.

Fix: look at the OPTIONS row in the Network tab and check its status and which server sent it. The reverse proxy guide shows a working setup and the paths to expose.

If the message says instead that a request header “is not allowed by Access-Control-Allow-Headers”, your code is sending a custom header to Keycloak, often through a global HTTP client interceptor. The simplest fix is to stop sending that header to Keycloak, and the Keycloak 26.5.0 release notes describe an SPI option, spi-cors--default--allowed-headers, for allowing environment-specific headers if you really need it.

Login works, then the token POST fails with a CORS error

The user signs in, the browser returns to your app with ?code=... in the URL, and then the token request is blocked.

Cause: the login and the return trip are full-page navigations, which CORS does not restrict, so a correct redirect URI gets you this far. The token exchange is the first request your JavaScript makes, and it needs Web origins. Valid redirect URIs does not fill that field for you unless you use +.

Fix: add the origin of the redirect URI, not the URI itself. For a redirect URI of https://myapp.com/callback, the Web origins entry is https://myapp.com.

CORS works in development but fails in production

Cause: the production origin differs from the one you tested, and each part counts: http and https, www.myapp.com and myapp.com, and a different port are all different origins. It is also common for a dev server proxy to hide the problem, because your browser then talks to one origin and never makes a cross-origin request at all.

Fix: read the origin from the production error and add it to the production client. We recommend one client per environment, so that http://localhost:3000 never sits in the Web origins of a production client. If production has a proxy that development lacks, the next section is the one to check.

Somewhere to run this that stays patched

Everything above works the same on Skycloak, because it is real upstream Keycloak rather than a fork. What changes is who handles the upgrades, backups and security patches afterwards.

The ‘Access-Control-Allow-Origin’ header contains multiple values

The 'Access-Control-Allow-Origin' header contains multiple values 'https://myapp.com, *',
but only one is allowed.

Cause: Keycloak and a proxy in front of it both add the header, and browsers accept “a value that is either a single origin or null” here, not a list (MDN, multiple origins error). A proxy can also fail in the other direction, because a proxy_hide_header line removes the header Keycloak sent, and then you get the “no header is present” error with a correct client.

Fix: let Keycloak own the CORS headers on its own paths, and let OPTIONS requests through to it. Here is the nginx version:

# Wrong: adds a second header on top of Keycloak's
location / {
    add_header Access-Control-Allow-Origin *;
    proxy_pass http://keycloak:8080;
}

# Right: Keycloak sets the CORS headers
location / {
    proxy_pass http://keycloak:8080;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
}

A CORS error on a redirect to /protocol/openid-connect/auth

If the blocked URL ends in /auth?... and the message includes “redirected from”, no Web origins value will help.

Cause: your API answered an AJAX call with a redirect to the login page, and the browser tried to follow it as a cross-origin request. The login page is meant for full-page navigation rather than for fetch calls, so the fix belongs in your API and your frontend.

Fix: make the API answer 401 to an unauthenticated AJAX call, and have the frontend start the login with a full-page navigation.

Web origins for public clients, confidential clients and a BFF

Client type Who calls Keycloak What to do
Public client (SPA with keycloak-js, authorization code with PKCE) The browser Set Web origins to the app’s origin or +
Confidential client (server-side app) Your server No browser CORS applies to these calls
Backend for frontend (BFF) Your BFF server, using a confidential client Configure CORS on the BFF if the browser calls it from another origin

A browser app must use a public client, as “there is no secure way to store client credentials in a client-side application” (Keycloak JavaScript adapter). Server-side calls carry no Origin header, and in the 26.8.1 source Keycloak’s CORS code skips those requests. In the BFF pattern, the browser talks to your backend and your backend talks to Keycloak, so a CORS error between the browser and the BFF is yours to fix on the BFF.

Test Web origins with a real POST, not a preflight

An OPTIONS test with curl only shows how a preflight is answered, and because that request has no body, it does not name the client whose Web origins you want to test. Send the real request instead, with an origin and a deliberately invalid refresh token, against a public client:

curl -i -X POST \
  -H "Origin: https://myapp.com" \
  -d "grant_type=refresh_token&client_id=my-spa&refresh_token=invalid" \
  "https://auth.example.com/realms/myrealm/protocol/openid-connect/token"

An allowed origin should get an error about the token, with the CORS header present:

HTTP/1.1 400 Bad Request
Access-Control-Allow-Origin: https://myapp.com

Run it again with Origin: https://not-listed.example. That response should have no Access-Control-Allow-Origin header, and on a release with the upgrading guide’s change described above it should be a 403. Once your app gets tokens, you can inspect them with the JWT decoder.

A CORS error on your own API

Web origins only controls the responses Keycloak sends. If the blocked URL belongs to your API, your API or its gateway has to return the CORS headers, and no Keycloak setting will change that. An access token can carry an allowed-origins claim, since the web-origins scope “is used to add allowed web origins to the access token allowed-origins claim” (Keycloak Server Administration Guide), but your server still has to act on it or on its own list. The Keycloak CORS error troubleshooting post is the diagnostic path for this case, with Express and Spring Boot examples.

Frequently asked questions

Is there a global CORS setting in Keycloak?

No. Allowed origins are set per client through Web origins, as described in the Keycloak basic client configuration. The spi-cors--default--allowed-headers option adds request headers, but it does not add origins.

Can Web origins use a wildcard subdomain?

Keycloak’s documentation does not describe one, and the admin console’s help text names only + and * as special values, so do not rely on https://*.myapp.com and list each origin as its own entry.

Should Web origins be empty on a confidential client?

It can be if only your server calls Keycloak with that client, because server-side requests send no Origin header. An empty list allows no browser origin, so a browser calling the token endpoint with that client will get a CORS error.

What to do next

Check the client’s Web origins against the origin shown in the browser error, and save the exact value or +. If the blocked URL is your own API, read Keycloak CORS error troubleshooting, and if you are hitting something other than CORS, the top 10 Keycloak errors is a good place to look next.

Web origins stays your setting on any Keycloak, including ours, because it depends on where your app runs. If you would rather not host and maintain Keycloak yourself, Skycloak managed Keycloak runs it for you, and our first application tutorial shows Web Origins being set on the client.

Somewhere to run this that stays patched

Everything above works the same on Skycloak, because it is real upstream Keycloak rather than a fork. What changes is who handles the upgrades, backups and security patches afterwards.

Guilliano Molaire
Written by
Founder, Skycloak

Guilliano is the founder of Skycloak and a cloud infrastructure specialist with deep expertise in product development and scaling SaaS products. He discovered Keycloak while consulting on enterprise IAM and built Skycloak to make managed Keycloak accessible to teams of every size.

© 2026 Skycloak. All Rights Reserved. Design by Yasser SolimanKeycloak™ is a trademark of the Linux Foundation. Skycloak is not affiliated with the Keycloak project.