ZaptoS
ZaptoS

Reputation: 141

No 'Access-Control-Allow-Origin' header for restricted access by signed cookies CloudFront

I have a strange problem. First of all,I need to tell that I read all articles about this problem which are connected with setting of CloudFront and S3,and it's not my case.

I configurated an access to files in the bucket through the signed cookies, and when I made the request from browser, the file was immediatly opened, but there were no Access-Control-Allow-Origin in the response. When I change the signed cookies to the signed urls, I began getting this header in the response without changing any other CORS permissions and settings.

How can I fix this strange bug? Have you ever see the same behavior?

My settings & configuration:

1) Cookies sets for ".mydomain.com", I make requests from "application.mydomain.com" to "cf.mydomain.com" (it's a mapped CNAME for cloudfront distribution)

2) S3 CORS settings 
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
    <CORSRule>
        <AllowedOrigin>http://application.mydomain.com</AllowedOrigin>
        <AllowedMethod>POST</AllowedMethod>
        <AllowedMethod>HEAD</AllowedMethod>
        <AllowedMethod>GET</AllowedMethod>
        <AllowedMethod>PUT</AllowedMethod>
        <AllowedMethod>DELETE</AllowedMethod>
        <MaxAgeSeconds>3000</MaxAgeSeconds>
        <AllowedHeader>*</AllowedHeader>
    </CORSRule>
</CORSConfiguration>

Also I used instead of
     <AllowedOrigin>http://application.mydomain.com</AllowedOrigin> 
some other options as
     <AllowedOrigin>*</AllowedOrigin>
     <AllowedOrigin>http://*.mydomain.com</AllowedOrigin>
but without success.

3) Cloudfront settings

-Viewer Protocol Policy
HTTP and HTTPS

-Allowed HTTP Methods
GET, HEAD

-Cached HTTP Methods
GET, HEAD (Cached by default)

-Forward Headers
Whitelist

-Whitelist Headers
Access-Control-Request-Headers
Access-Control-Request-Method
Origin

-Forward Cookies
All

-Forward Query Strings
Yes

Upvotes: 0

Views: 434

Answers (1)

ZaptoS
ZaptoS

Reputation: 141

If you work with jquery library, do not forget to setup xhrFields: {withCredentials: true}

It helped me.

Upvotes: 1

Related Questions