goauthentik / authentik

The authentication glue you need.
https://goauthentik.io
Other
12.78k stars 850 forks source link

OAuth CORS does not take into account RegEx #3084

Open fayalalebrun opened 2 years ago

fayalalebrun commented 2 years ago

Describe the bug CORS rules are specified in the same field as redirect URLs. However, in contrast to redirect urls, CORS requests do not seem to use any form of RegEx.

https://github.com/goauthentik/authentik/blob/350f0d836580f4411524614f361a76c4f27b8a2d/authentik/providers/oauth2/utils.py#L44 In this line the URL is parsed and shortly afterwards compared directly to any of the passed rules. This function does not take any regex into account.

To Reproduce Steps to reproduce the behavior:

  1. Go to 'Providers'
  2. Create an OAuth Provider
  3. Specify ".*" in the Redirect URIs field
  4. Perform a request to the application/o/<slug>/.well-known/openid-configuration endpoint.
  5. The CORS headers in the response will be missing.

Expected behavior CORS allowed origins respect the same RegEx rules as redirect URLs.

Logs

server_1       | {"allowed": [".+", "http://.*"], "event": "CORS: Origin is not an allowed origin", "host": "authentik.redacted.io", "level": "warning", "logger": "authentik.providers.oauth2.utils", "pid": 23, "request_id": "7197b556022548e1849a1814014b355f", "requested": ["http", "localhost:3000", "", "", "", ""], "timestamp": "2022-06-13T17:15:51.891612"}

Version and Deployment (please complete the following information):

Additional context I would like to accept CORS requests from a range of subdomains. Possible workarounds are appreciated.

BeryJu commented 2 years ago

just FYI this would've also been broken with the old system of allowing "*" as redirect_uri

codingCoffee commented 1 year ago

Hey! I'm hosting authentik being a reverse proxy (nginx) and my application is unable to access the openid-configuration because authentik is raising a CORS error. I tried putting * as the redirect_uri and also tried using the URL of my application. The CORS error persists in both cases. If there any fix / workaround for this?

skiwheelr commented 1 year ago

I am also having this issue. Tried . and .+

rafalkrupinski commented 1 year ago

What's the workaround?

masfaraud commented 11 months ago

any update?

fooware commented 6 months ago

@BeryJu; this issue was marked as bug/confirmed since the middle of 2022, any news?

The help text when creating / editing the provider doesn't really make it clear that you need to use different formats for the "Redirect URIs" and "Origins" even though they are in the same input box, nor explicitly mention that the suggested wildcard solution will not work for CORS.

image

Granted, we are running version 2023.10.7, so there might have been an update to this issue after that.

idc77 commented 4 months ago

This is still an issue.

The "workaround" is to explicitly state every single redirect_uri.

Also this IDP or whatever you want to call authentik, needs a dev mode. In Keycloak one can just create a new client and use that as a dev client, with all the insecure redirect_uris. Here you need to create a completely new application.

I also don't like how all the userbase is shared across all applications. This collides with EUGDPR or rather the digital markets act.

solomonaboyeji commented 3 months ago

This issue does not make preview pages (URLs) work as they always have different sub-domain anytime a new PR is created.

fooware commented 1 month ago

I also don't like how all the userbase is shared across all applications. This collides with EUGDPR or rather the digital markets act.

@idc77, could you elaborate on that statement?