CORS request not working in Safari

I encountered the same error when making an XHR request against a file in Amazon S3. On Safari 7 it was failing. I know you’re not using Amazon S3, but I thought I’d post in case this solution helped others.

The problem was that Safari 7 set the Access-Control-Request-Headers header to “origin, x-requested-with”, but my AWS CORS configuration only allowed “x-requested-with”:

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
    <CORSRule>
        <AllowedOrigin>*</AllowedOrigin>
        <AllowedMethod>GET</AllowedMethod>
        <MaxAgeSeconds>3000</MaxAgeSeconds>
        <AllowedHeader>Authorization</AllowedHeader>
        <AllowedHeader>x-requested-with</AllowedHeader>
    </CORSRule>
</CORSConfiguration>

I added “origin” as an allowed header and everything worked fine.

        <AllowedHeader>origin</AllowedHeader>

Note: the AllowedOrigin of * is for development purposes only. See @andes comment below for more information.

Leave a Comment