Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong CORS headers when duplicate header in Access-Control-Request-Headers in v0.40.8 #1208

Open
4 of 5 tasks
wewelll opened this issue Dec 26, 2024 · 2 comments
Open
4 of 5 tasks
Labels
bug Something is not working.

Comments

@wewelll
Copy link

wewelll commented Dec 26, 2024

Preflight checklist

Ory Network Project

No response

Describe the bug

Today I've tried to update oatheeper from v0.40.7 to v0.40.8. I'm using as API gateway in front of my backend services.

It created a very odd bug for Firefox users: the CORS headers stopped working for them. But everything was working correctly on Google Chrome...

I reproduced the bug in my local environment, and did a bit of debugging to understand what is going on.
It seems that in the v0.40.8 Oathkeeper does not return the expected CORS headers if they're duplicated.

For instance if I have a header Access-Control-Request-Headers: b3,traceparent,x-b3-sampled,x-b3-spanid,x-b3-traceid it will work, but if I have Access-Control-Request-Headers: b3,b3,traceparent,x-b3-sampled,x-b3-spanid,x-b3-traceid it won't work.

The only difference is that the b3 is duplicated in the second version. I don't know why the b3 is duplicated by the way and I don't have control over it. But the server should still return the correct CORS headers even when the header is duplicated.

Reproducing the bug

When I run this it works

  curl http://localhost:4455/v0/identity/073f80e1-3363-40dc-9292-62ceaf75a34a \
   -X OPTIONS \
   -H "Access-Control-Request-Method: GET" \
   -H "Access-Control-Request-Headers: b3,traceparent,x-b3-sampled,x-b3-spanid,x-b3-traceid" \
   -H "Origin: http://localhost:4000" \
   -v
* Host localhost:4455 was resolved.
* IPv6: ::1
* IPv4: 127.0.0.1
*   Trying [::1]:4455...
* Connected to localhost (::1) port 4455
> OPTIONS /v0/identity/073f80e1-3363-40dc-9292-62ceaf75a34a HTTP/1.1
> Host: localhost:4455
> User-Agent: curl/8.7.1
> Accept: */*
> Access-Control-Request-Method: GET
> Access-Control-Request-Headers: b3,traceparent,x-b3-sampled,x-b3-spanid,x-b3-traceid
> Origin: http://localhost:4000
>
* Request completely sent off
< HTTP/1.1 204 No Content
< Access-Control-Allow-Credentials: true
< Access-Control-Allow-Headers: b3,traceparent,x-b3-sampled,x-b3-spanid,x-b3-traceid
< Access-Control-Allow-Methods: GET
< Access-Control-Allow-Origin: http://localhost:4000
< Vary: Origin, Access-Control-Request-Method, Access-Control-Request-Headers
< Date: Thu, 26 Dec 2024 21:17:52 GMT
<
* Connection #0 to host localhost left intact

But if I run this it does not work

 curl http://localhost:4455/v0/identity/073f80e1-3363-40dc-9292-62ceaf75a34a \
   -X OPTIONS \
   -H "Access-Control-Request-Method: GET" \
   -H "Access-Control-Request-Headers: b3,b3,traceparent,x-b3-sampled,x-b3-spanid,x-b3-traceid" \
   -H "Origin: http://localhost:4000" \
   -v
* Host localhost:4455 was resolved.
* IPv6: ::1
* IPv4: 127.0.0.1
*   Trying [::1]:4455...
* Connected to localhost (::1) port 4455
> OPTIONS /v0/identity/073f80e1-3363-40dc-9292-62ceaf75a34a HTTP/1.1
> Host: localhost:4455
> User-Agent: curl/8.7.1
> Accept: */*
> Access-Control-Request-Method: GET
> Access-Control-Request-Headers: b3,b3,traceparent,x-b3-sampled,x-b3-spanid,x-b3-traceid
> Origin: http://localhost:4000
>
* Request completely sent off
< HTTP/1.1 204 No Content
< Vary: Origin, Access-Control-Request-Method, Access-Control-Request-Headers
< Date: Thu, 26 Dec 2024 21:17:43 GMT
<
* Connection #0 to host localhost left intact

Relevant log output

No response

Relevant configuration

No response

Version

v0.40.8

On which operating system are you observing this issue?

None

In which environment are you deploying?

Ory Network

Additional Context

No response

@wewelll wewelll added the bug Something is not working. label Dec 26, 2024
@aeneasr
Copy link
Member

aeneasr commented Jan 2, 2025

Unfortunately I have no idea what could cause this.

@wewelll
Copy link
Author

wewelll commented Jan 3, 2025

it could come from this middleware : https://github.com/ory/x/blob/master/corsx/middleware.go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is not working.
Projects
None yet
Development

No branches or pull requests

2 participants