authentik icon indicating copy to clipboard operation
authentik copied to clipboard

application/o/authorize endpoint missing CORS headers

Open mdelpire opened this issue 1 year ago • 4 comments

Describe the bug Not sure it is a bug or a misconfiguration somewhere... Web application is calling the /application/o/authorize/ endpoint from the browser.

It is failing with the message in the Chrome Debug Console

Access to fetch at 'https://auth.mydomain.com/application/o/authorize/?client_id=xxxxxxxxxx&redirect_uri=https%3A%2F%2Forigin.domain.com%2Foutpost.goauthentik.io%2Fcallback%3FX-authentik-auth-callback%3Dtrue&response_type=code&scope=email+profile+ak_proxy+openid&state=m2qJvqqq3tNbVgvzIgz7h6l3w4-hErhUX1fd5WmLJ_g' (redirected from 'https://origin.domain.com/info') from origin 'https://origin.domain.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request.

I do not see the headers : access-control-allow-origin: https://origin.domain.com

To Reproduce Steps to reproduce the behavior:

Create a Forward auth (Single Applicaiton) provider and set External host to https://origin.domain.com Make sure the user was already logged in --> no new login requested. Try to get authorisation from https://auth.mydomain.com/application/o/authorize/

Expected behavior Preflight contains CORS headers access-control-allow-origin: https://origin.domain.com

Version and Deployment (please complete the following information):

  • authentik version: 2024.4.2
  • Deployment: docker-compose

mdelpire avatar Jun 10 '24 10:06 mdelpire

Seeing this also

efaden avatar Jun 10 '24 18:06 efaden

This is probably because the preflight request is returning a 302 found instead of a 200 success.

Towerism avatar Jun 23 '24 19:06 Towerism

It might be the case as if I clear the cache everything works fine. How can I prevent this 302 and force to get the request?

On Sun, Jun 23, 2024 at 9:59 PM Martin Fracker, Jr. < @.***> wrote:

This is probably because the preflight request is returning a 302 found instead of a 200 success.

— Reply to this email directly, view it on GitHub https://github.com/goauthentik/authentik/issues/10057#issuecomment-2185307431, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGA4IOI6DKPYOQEBEYOQ67LZI4SLFAVCNFSM6AAAAABJB75OWOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCOBVGMYDONBTGE . You are receiving this because you authored the thread.Message ID: @.***>

mdelpire avatar Jun 26 '24 11:06 mdelpire

I have exact the same issue. in "InPrivate"/Incognito windows it works. but in normal window I get blocked by CORS policy.

authentik version: 2024.6.2 deployment: helm kubernetes with nginx ingress

addich avatar Aug 05 '24 09:08 addich

Exact same issue. Fresh installation. K0s and ingress with nginx + load balancer + cloudflare.

Deployed with helm. Latest version.

scipe avatar Sep 22 '24 22:09 scipe

Same issue. Makes Authentik proxy unusable on version 2024.8.2.

PrivateGER avatar Sep 25 '24 09:09 PrivateGER

Hello, same issue here.

When a user made a post request on my webapp and their token is invalid, it will redirect to the authorize endpoint. In this case, the browser will make a preflight/OPTIONS request that will return 200 without the header access-control-allow-origin. That way, the next GET request will be blocked by the browser.

Looking at the code, it seems that the authorize endpoint doesn't call the method cors_allow. So any OPTIONS request to that endpoint will fail.

I don't know if this is expected, though :/

QHivert avatar Sep 26 '24 16:09 QHivert

Also seeing this since update to 2024.8.2/2024.8.3

0xEmma avatar Oct 02 '24 16:10 0xEmma

Also facing this same issue. In my case, the application works fine when i'm logged in. But, i have set some paths in the Unauthenticated Paths list, and when i try to access any of these paths from an unauthenticated browser, i get CORS errors.

image

yurividal avatar Oct 07 '24 08:10 yurividal

I have exact the same issue.

Samppady avatar Oct 24 '24 06:10 Samppady

Same here, I suspect this is causing issues with properly getting scopes from authentik: username, email, ak_proxy, etc...

MahmoudAlyuDeen avatar Oct 26 '24 23:10 MahmoudAlyuDeen

Also running in to this on 2024.8.3

dankozlowski avatar Nov 01 '24 23:11 dankozlowski

I have the same issue using nginx proxy manager on 2024.10.2

StianHaugland1 avatar Nov 20 '24 20:11 StianHaugland1

This is still an issue in 2024.12.0.

joriskt avatar Dec 22 '24 11:12 joriskt

+1, have the same issue when trying to reverse proxy to this project https://github.com/will-moss/erin

mdbook avatar Jan 04 '25 03:01 mdbook

Same issue using Caddy as reverse proxy (for Immich)

Pyramiden avatar Jan 29 '25 07:01 Pyramiden

I'm running traefik in front of the outpost (embedded), adding something like this in the labels and assigning the middleware to the router fixes the issue for now:

traefik.http.middlewares.authentik-cors.headers.accessControlAllowOriginListRegex: ^https://.+\.(subdomain1|subdomain2)\.example\.org

RomRider avatar Feb 02 '25 02:02 RomRider

Same issue using Caddy as reverse proxy (for Immich)

exactly the same issuer with ingress-nginx as reverse proxy.

CodeAdminDe avatar Feb 22 '25 17:02 CodeAdminDe

same here. using traefik and cloudflare

wm-ek avatar Feb 24 '25 10:02 wm-ek

Right-clicking and Reload the page always temporarily resolves the issue. 🙂 It seems the browser is handling the authentication session cache, which allows it to bypass the CORS preflight check. At least works

nvroot avatar Feb 27 '25 19:02 nvroot

I am also seeing this issue myself and have spent hours trying to troubleshoot.

Anyone got anywhere as of yet?

witalit avatar Mar 01 '25 20:03 witalit

Hello, After some research, I've found that authorization endpoint not doing cors policy is not a bug but is designed that way: Best Current Practice for OAuth 2.0 Security.

So the problem is our application does a cross-origin request to this endpoint, which should not handle it.

In my case, the webapp was making a $http post request to my server, which responds a 302 to the authorize endpoint, triggering a cors policy request and failure...

I fix that by making my server responds an 200 with data: {"redirect": <authorize_endpoint_url>} to which the webapp does a simple get request and this works now.

Hope it can help!

QHivert avatar Mar 03 '25 09:03 QHivert

can u guide me bro where you've passed data..

axios.post(
                `https://localhost:9443/application/o/prepaid-card-fino-isu/end-session/`,
                { redirect: "https://localhost:9443/api/v3/flows/executor/default-provider-invalidation-flow" },  // Request body
                {
                    params: { // Query parameters
                        id_token_hint: idTokenHint,
                        post_logout_redirect_uri: "http://localhost:3000/home",
                        state: ""
                    },
                    headers: {
                        "Content-Type": "application/json"
                    },
                    mode: 'cors'
                }
            )
            .then(() => {
                console.log("Logout successful");
                setUserInfo(null);
                setIdTokenHint(null); // Clear token hint
                window.location.href = "http://localhost:3000/home"; // Redirect to Home/Login
            })
            .catch(error => console.error("Logout Error:", error));

here is the code snipt

dasHimanshuSekhar avatar Mar 10 '25 11:03 dasHimanshuSekhar

I'm using traefik as forward proxy and solved this issue by setting the Content-Security-Policy Header of authentik:

traefik.http.middlewares.contentsec.headers.contentsecuritypolicy=frame-ancestors 'self' https://<URL to application>;

Documentation: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/frame-ancestors

mad73923 avatar Mar 11 '25 20:03 mad73923