javascript - Safari fails CORS request after 302 redirect - Stack Overflow

I have problem with the way Safari handles CORS requests. Consider following scenario:DomainA hosts a p

I have problem with the way Safari handles CORS requests. Consider following scenario:

  1. DomainA hosts a page which makes a XHR request to DomainB (origin header is set to DomainA)
  2. DomainB returns 302 redirect do DomainC (origin header is set to null, which seems to be OK with RFC)
  3. DomainC return 200 response with actual content

This works in Chrome, FF, but it fails on Safari (tested on Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/600.8.9 (KHTML, like Gecko) Version/8.0.8 Safari/600.8.9).

When I make the request without xhr.withCredentials turned on, first, Safari makes a OPTIONS preflight request prior actual request to DomainC, which IMHO is not nessesary as all request are simple request, but that I can handle. Problem is Safari fails after preflight request to DomainC saying "Cannot make any request from null". I can bypass this by setting Access-Control-Allow-Origin to * and drop Access-Control-Allow-Credentials header (those are mutually exclusive), which would make this scenario work. However I still think this is not correct behavior.

Now, thing is I need credentials to be passed by (and no, I can not pass it some other way as it depends on some third party servers). So, let's set

xhr.withCredentials

to true and we are back to "Cannot make any request from null" and now even wildcarding Access-Control-Allow-Credentials does not help.

I think all CORS headers are set properly, but please feel free to check me. Test example can be found here:

What is going on here? Is it a bug or am I missing something?

Thanks for answers

I have problem with the way Safari handles CORS requests. Consider following scenario:

  1. DomainA hosts a page which makes a XHR request to DomainB (origin header is set to DomainA)
  2. DomainB returns 302 redirect do DomainC (origin header is set to null, which seems to be OK with RFC)
  3. DomainC return 200 response with actual content

This works in Chrome, FF, but it fails on Safari (tested on Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/600.8.9 (KHTML, like Gecko) Version/8.0.8 Safari/600.8.9).

When I make the request without xhr.withCredentials turned on, first, Safari makes a OPTIONS preflight request prior actual request to DomainC, which IMHO is not nessesary as all request are simple request, but that I can handle. Problem is Safari fails after preflight request to DomainC saying "Cannot make any request from null". I can bypass this by setting Access-Control-Allow-Origin to * and drop Access-Control-Allow-Credentials header (those are mutually exclusive), which would make this scenario work. However I still think this is not correct behavior.

Now, thing is I need credentials to be passed by (and no, I can not pass it some other way as it depends on some third party servers). So, let's set

xhr.withCredentials

to true and we are back to "Cannot make any request from null" and now even wildcarding Access-Control-Allow-Credentials does not help.

I think all CORS headers are set properly, but please feel free to check me. Test example can be found here: http://a.ihatesafari.

What is going on here? Is it a bug or am I missing something?

Thanks for answers

Share asked Sep 1, 2015 at 13:27 flopinflopin 1011 silver badge3 bronze badges 1
  • 1 It even fails in the simpler case of DomainA making an XHR to DomainA and redirecting to DomainC. – hrdwdmrbl Commented Oct 19, 2015 at 20:32
Add a ment  | 

1 Answer 1

Reset to default 5

I was experiencing this issue as well and found this bug from 2012 that appears to be describing it. Running the test code referenced in the bug in FF / Chrome / Safari yielded failures only in Safari. It appears that the bug has not been patched.

Ultimately to get around this, I modified our HTTP API to add an optional query parameter to trigger a different response that returned a 200 OK with a JSON body containing the url that the client was to follow. Unfortunately if you're a consumer of someone else's HTTP API this won't help much.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744930975a4601735.html

相关推荐

  • javascript - Safari fails CORS request after 302 redirect - Stack Overflow

    I have problem with the way Safari handles CORS requests. Consider following scenario:DomainA hosts a p

    1天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信