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

set Access-Control-Allow-Origin header according to origin header #3686

Closed
irgb opened this issue Jul 27, 2018 · 8 comments
Closed

set Access-Control-Allow-Origin header according to origin header #3686

irgb opened this issue Jul 27, 2018 · 8 comments
Assignees
Labels
area/middleware kind/enhancement a new or improved feature. priority/P2 need to be fixed in the future status/5-frozen-due-to-age
Milestone

Comments

@irgb
Copy link

irgb commented Jul 27, 2018

Feature

What did you expect to see?

It seems that traefik only support set Access-Control-Allow-Origin to a fixed value such as "Access-Control-Allow-Origin: *", "Access-Control-Allow-Origin: https://google.com" via traefik.frontend.headers.customResponseHeaders.

It would be better if we can set Access-Control-Allow-Origin to origin if origin satisfy requirements.
for example:

origin: http://domain1.google.com -> Access-Control-Allow-Origin: http://domain1.google.com
origin: http://domain2.google.com -> Access-Control-Allow-Origin: http://domain2.google.com

@mmatur
Copy link
Member

mmatur commented Jul 30, 2018

#1292

@mmatur mmatur added kind/enhancement a new or improved feature. priority/P2 need to be fixed in the future area/middleware and removed status/0-needs-triage labels Jul 30, 2018
@dtomcej dtomcej self-assigned this Aug 20, 2018
@dtomcej
Copy link
Contributor

dtomcej commented Aug 21, 2018

@irgb I have a branch where I am working on creating CORS headers, but there is a fair bit of logic involved. Should have something up in the next few days.

@dtomcej dtomcej mentioned this issue Aug 21, 2018
5 tasks
@gheibia
Copy link
Contributor

gheibia commented Jan 16, 2019

@dtomcej does this mean that when configured, Traefik returns not only the origin, but also "Vary: Origin" header?

@dtomcej
Copy link
Contributor

dtomcej commented Jan 17, 2019

@gheibia This issue does not implement caching headers, since that can easily be configured by the current customheaders configuration. The Vary header does not require any dynamic content from the request, AFAIK.

If it does, it would be a follow-up feature request IMO

@gheibia
Copy link
Contributor

gheibia commented Jan 18, 2019

@dtomcej

Quoting mozilla's spec (mentioned in the PR):

If the server sends a response with an Access-Control-Allow-Origin value that is an explicit origin (rather than the "*" wildcard), then the response should also include a Vary response header with the value Origin — to indicate to browsers that server responses can differ based on the value of the Origin request header.

From that I assumed the Vary: Origin header goes hand-in-hand with the new behaviour where Traefik can be configured with a list of origins (in order to return the origin if there is a match) instead of a static value. However, I'd be happy to take that on after you're done with your PR.

@dtomcej
Copy link
Contributor

dtomcej commented Jan 20, 2019

@gheibia,

Good Catch on the Vary: Origin header section in that spec. I will update the PR to include it.

Traefik can be configured with a list of origins

I don't think that is how it will work.

From my research https://www.w3.org/TR/cors/#access-control-allow-origin-response-header, it would seem that only 3 options are available as a response:

by returning the value of the Origin request header, "*", or "null" in the response

I may be mis-reading the spec, but that's how I read it.

@gheibia
Copy link
Contributor

gheibia commented Jan 20, 2019

No, you're right about how it should work. By list of origins I was referring to Traefik's to-be configuration. In other words, Traefik could have a set of whitelisted origins using which it determines whether it should return the Origin. For example, if the configuration lists out "https://abc.com" and "https://xyz.com" as trusted origins, then a request with "https://xyz.com" as its origin would cause Traefik to return:

Access-Control-Allow-Origin: https://xyz.com
Vary: Origin

Of course, if the configuration is null or *, then regardless of the origin header of the request, the server either adds nothing to the response header or adds Access-Control-Allow-Origin: * respectively.

@traefiker traefiker added this to the 2.0 milestone Apr 2, 2019
@traefiker
Copy link
Contributor

Closed by #3809.

@traefik traefik locked and limited conversation to collaborators Sep 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/middleware kind/enhancement a new or improved feature. priority/P2 need to be fixed in the future status/5-frozen-due-to-age
Projects
None yet
Development

No branches or pull requests

5 participants