New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 741958 link

Starred by 3 users

Issue metadata

Status: Assigned
Owner:
Buried. Ping if important.
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 3
Type: Compat



Sign in to add a comment

Amazon S3 CORS implementation primes cache to reject cross-origin requests

Project Member Reported by sdy@chromium.org, Jul 13 2017

Issue description

A web developer friend just reached out to me about what they thought was a Chrome bug, but turns out to (maybe) be an issue with a number of CORS implementations, including S3, which other web devs have run into since CORS was launched. Here's some discussion:

-  Issue 409090  — opened in 2014, last comment eight hours ago!
- https://forums.aws.amazon.com/thread.jspa?threadID=112772
- https://stackoverflow.com/questions/44800431/
- https://stackoverflow.com/questions/31732533/

S3 (and, it sounds like, some common CORS libraries) only adds CORS headers to a response when the request includes an Origin header. If a resource is loaded first without CORS (e.g. in an `img` tag), and later with CORS, the second request hits the cache and gets rejected.

Poking through the spec, it looks like S3 should either be sending CORS headers all the time, or send a `Vary: Origin` header when CORS is enabled for a resource.

I think it would be great if we could:

1. Come up with a recommendation for how servers should handle CORS headers.
2. Reply to the crbug, and at least one of the Stack Overflow questions, with our recommendation.
3. Ask Amazon to fix S3.
 

Comment 1 by sdy@chromium.org, Jul 13 2017

I'm not sure if I cc'd the right people on this, or if crbug is the right place to have this conversation. Feel free to add/remove people, tell me to make an email thread instead, or nix Restrict-View-Google :).
Cc: -tyoshino@chromium.org
Owner: tyoshino@chromium.org
Status: Assigned (was: Unconfirmed)
Either of the solutions you listed should work. We've been suggesting these solutions for similar questions.

If you want to allow multiple origins to use the resource but not everyone (i.e. not by the wildcard), you need to use the Vary header. Otherwise, you can respond to no-cors requests with the wildcard or the single origin you want to accept which the fetch algorithm just ignores for the no-cors requests but will be investigated for future CORS-enabled ones.

Comment 3 by sdy@chromium.org, Jul 13 2017

OK, that's reassuring. Is there anyone at Amazon we could talk to about making their products work like this? A lot of people seem to run into this problem with S3, and I think they offer CORS-specific settings but not a way to set arbitrary response headers.

Comment 4 by mkwst@chromium.org, Jul 13 2017

If you don't mind dropping `Restrict-View-Google`, I'd be happy to forward this bug to folks I know at Amazon.

Comment 5 by sdy@chromium.org, Jul 13 2017

Labels: -Restrict-View-Google
Sure thing.

Comment 6 by sdy@chromium.org, Jul 13 2017

Summary: Amazon S3 CORS implementation primes cache to reject cross-origin requests (was: Amazon S3 doing CORS wrong?)
I'm the friend. Firefox does not fire a cache hit in this case. Since the spec doesn't say if CORS headers are only returned if the Origin header is returned (S3's implementation) I think it is ambiguous what is the correct caching behavior. My guess is Firefox includes the Origin header in its cache key, while Chrome does not. I think a clarification in the spec might be helpful as well.

This was a frustrating one to figure out. My fix here was to add crossorigin to the 'img' tag which seems suboptimal.
"If the Origin header is sent" is my intended language.

Comment 9 by sdy@chromium.org, Jul 14 2017

Firefox's behavior is interesting. I found a WONTFIX issue on their bug tracker similar to our  issue 409090 : https://bugzilla.mozilla.org/show_bug.cgi?id=696430
Firefox keys the cache on the credentials mode. I think that's how they avoid the issue.
FYI, the section about use of the Vary header has been improved recently by Mike Smith.

https://fetch.spec.whatwg.org/#cors-protocol-and-http-caches
Labels: Hotlist-EnamelAndFriendsFixIt
Labels: -Hotlist-EnamelAndFriendsFixIt
Cc: -mkwst@chromium.org
Owner: mkwst@chromium.org
Reassigning to mkwst@
This also came up in https://bugs.chromium.org/p/chromium/issues/detail?id=809891, which had some communications from reporters to their support.

Cc: toyoshim@chromium.org
 Issue 889362  has been merged into this issue.

Sign in to add a comment