Ajax GET请求的XSS问题

时间:2013-07-10 14:31:43

标签: javascript jquery http coffeescript xss

我有以下咖啡脚本执行某种登录:

signIn: (url, completion) ->
  $.ajax
    method: 'GET'
    url: url
    dataType: 'json'
    error: (jqXHR, status, errorThrown) ->
      completion false, errorThrown
    success: (data)->
      completion true, data.Identifier

当我在浏览器中检查给定的URL时,我得到了有效的JSON响应。

但是,当使用JavaScript执行此调用时,我在控制台中收到以下错误。请注意,我更改了混淆的URL:

XMLHttpRequest cannot load http://my.servicedomain.com/session/someIdentifier?access_token=secret. 
Origin http://html.server.net is not allowed by Access-Control-Allow-Origin.

这些是我的标题,我从my.servicedomain.com服务器获取:

HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Length: 1417
Content-Type: application/json; charset=utf-8
Expires: -1
Server: Microsoft-IIS/8.0
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS
Access-Control-Allow-Headers: Authorization
Server: Microsoft-IIS/8.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
X-Powered-By: ASP.NET
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS
Access-Control-Allow-Headers: Authorization
Date: Wed, 10 Jul 2013 14:24:35 GMT
Vary: Accept-Encoding
Content-Encoding: gzip
Connection: Keep-Alive

为什么我会收到此错误,即使我在响应标头中有Access-Control-Allow-Origin: *

1 个答案:

答案 0 :(得分:0)

我自己刚刚找到了答案。我知道我的回复中有重复的标题,但我认为这不是问题。

根据CORS Spec

,这似乎是一个问题
  

如果响应包含零个或多个Access-Control-Allow-Origin标头值,则返回失败并终止此算法。

这也在本SO篇中描述:

Will duplicate "Access-Control-Allow-Origin: *" headers break CORS?