aldy120 / s3-note

Note for Amazon S3
0 stars 0 forks source link

Mysterious CORS Error #9

Open aldy120 opened 4 years ago

aldy120 commented 4 years ago

https://jsfiddle.net/ugv6jfyd/?fbclid=IwAR0d_5twupCY8BPSeUapx_jRwkDQ5RkbTPeTyR72OygbA0Ka3dIlylYsxdc

This error only occurs when enable browser cache.

Request URL: https://s3-ap-northeast-1.amazonaws.com/cube.lichi-chen.com/images/logo.jpg
Referrer Policy: strict-origin-when-cross-origin
Accept-Ranges: bytes
Content-Length: 33309
Content-Type: image/jpeg
Date: Mon, 09 Mar 2020 12:56:28 GMT
ETag: "58bb35d338ec48bcc79028e58a3cc2f4"
Last-Modified: Thu, 11 Jul 2019 17:20:51 GMT
Server: AmazonS3
x-amz-id-2: XDMic3o0smdYmOAQHyoNK3vTvfeAv7NDmsZ2P5vmOTCg8doowix7BnMBLK3b6C+cOC0ZZqRDgbc=
x-amz-request-id: D71C36290F5060A2
DNT: 1
Referer: https://fiddle.jshell.net/
Sec-Fetch-Dest: empty
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36
aldy120 commented 4 years ago

Request to CloudFront

curl -H 'if-none-match: "e44ee85929713579291e899e2b6e2e08"' https://cube.lichi-chen.com/sdfawefaew -vo /dev/null
< HTTP/2 304 
< date: Mon, 09 Mar 2020 13:18:09 GMT
< access-control-allow-origin: *
< access-control-allow-methods: GET
< last-modified: Thu, 11 Jul 2019 17:20:51 GMT
< etag: "e44ee85929713579291e899e2b6e2e08"
< server: AmazonS3
< vary: Origin,Access-Control-Request-Headers,Access-Control-Request-Method
< x-cache: Error from cloudfront
< via: 1.1 b4ef37917b36c601eeeeb55cdda4288c.cloudfront.net (CloudFront)
< x-amz-cf-pop: SIN2-C1
< x-amz-cf-id: mURPvzEyg-Q2xn-2V5AkB4asfLQXTIoMcCTs3n1jozn3wh2KmXD8OQ==
< 
aldy120 commented 3 years ago

Possible solutions:

  1. S3 metadata cache-control
  2. img tag attribute: crossorigin
  3. response header set vary: origin
  4. Insert Origin header by CDN/proxy.
aldy120 commented 3 years ago

https://bugs.chromium.org/p/chromium/issues/detail?id=741958