hydra: Client allowed_cors_origins not working
Describe the bug
Enabling CORS support on the public endpoints seems to be working as expected by enabling the settings in the configuration, however when setting the allowed_cors_origins setting in the client, the additional origin URLs are not being allowed.
Reproducing the bug
Steps to reproduce the behavior:
- Create a hydra environment version 1.3.2 with the below configuration
- create an authorization_code client
my_clientwith allowed_cors_origin set to an alternate (additional) Origin URL - POST to the /oauth2/token endpoint with the Origin: header (ie ‘Origin: https://client-app.example.com’), and client_id: my_client in the body of the request.
- Request should return the following response headers access-control-allow-credentials: true access-control-allow-origin: https://client-app.example.com
Server logs
Server configuration
Expected behavior
expect https://client-app.example.com to be an allowed origin
Environment
- Version: v1.3.2
- Environment: Docker
Additional context
Add any other context about the problem here.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 1
- Comments: 26 (13 by maintainers)
Commits related to this issue
- refactor: cleanup the code for CORS handling (#1959) See #1754 — committed to ory/hydra by harsimranmaan 4 years ago
- fix: client specific CORS Closes #1754 — committed to ory/hydra by aeneasr 2 years ago
- fix: client specific CORS Closes #1754 — committed to ory/hydra by aeneasr 2 years ago
- fix: client specific CORS Closes #1754 — committed to ory/hydra by aeneasr 2 years ago
- fix: backport fix for client specific CORS (#1754) — committed to navnext/hydra by har07 2 years ago
- fix: backport fix for client specific CORS (#1754) (#3163) — committed to ory/hydra by har07 2 years ago
- fix: client specific CORS Closes #1754 — committed to ory/hydra by aeneasr 2 years ago
- fix: client specific CORS Closes #1754 — committed to ory/hydra by aeneasr 2 years ago
- fix: client specific CORS Closes #1754 — committed to ory/hydra by aeneasr 2 years ago
- fix: client specific CORS Closes #1754 — committed to ory/hydra by aeneasr 2 years ago
- fix: client specific CORS Closes #1754 — committed to ory/hydra by aeneasr 2 years ago
- fix: client specific CORS Closes #1754 — committed to ory/hydra by aeneasr 2 years ago
Nice find, it actually appears that the server-based origin only works if the server config is either
or
but not if a concrete value is set. That’s definitely a bug!
Instead of doing a check here
https://github.com/ory/hydra/blob/master/driver/cors.go#L60-L70
we should merge these origins with values coming the client and then run the glob matching on top of that.
We can still keep the
alwaysAllowcheck to reduce request latency in cases where all origins are allowed.Ok at last I found the solution!
In order to pass the
client_idin basic-auth whentoken_endpoint_auth_method = none, you need to leave the colon after theclient_id.For example:
If you include a dummy password or omit the colon, it will not work.
Thank you very much @IronGeek !
Unfortunately, this still isn’t working as I would expect. (tested with version 1.5.2) Configuring
allowed_cors_originson the oauth client effectively does nothing, whatever I configure inserve.public.cors.allowed_originsis the only thing that’s honored.If I set
serve.public.cors.enabled=falseor just don’t set it, then I get no access-control headers returned at all regardless of what I set in the client for allowed_cors_origins.If I set
serve.public.cors.allowed_originsto “" that works, but only because it’s returning the Access-Control-Allow-Origin header of "” which effectively makes client configured cors obsolete.