简体   繁体   English

Ajax GET请求的XSS问题

[英]XSS Problems with Ajax GET Request

I have the following coffee script which performs some sort of login: 我有以下执行某些登录方式的coffee脚本:

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

When I check the given URL in the browser I get a valid JSON Response back. 当我在浏览器中检查给定的URL时,我得到一个有效的JSON响应。

However, when this call is executed using JavaScript I get the following error in the console . 但是,使用JavaScript执行此调用时,在控制台中出现以下错误。 Please note that I have changed the URLs for obfuscation: 请注意,我已经更改了混淆网址:

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.

These are my headers, which I get from the my.servicedomain.com server: 这些是我的标题,这些标题是从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

Why do I get this error, even though I have Access-Control-Allow-Origin: * in the response header? 即使响应头中有Access-Control-Allow-Origin: * ,为什么仍会出现此错误?

I have just figured out the answer myself. 我自己才知道答案。 I knew that I had duplicated headers in my response, but I was assuming this would not be a problem. 我知道我在响应中重复了标题,但是我以为这不是问题。

It looks like this is a Problem according to the CORS Spec : 根据CORS规范,这似乎是一个问题:

If the response includes zero or more than one Access-Control-Allow-Origin header values, return fail and terminate this algorithm. 如果响应包含零个或多个Access-Control-Allow-Origin标头值,则返回失败并终止此算法。

This is also described in this SO Thread: 此SO线程中也对此进行了描述:

Will duplicate "Access-Control-Allow-Origin: *" headers break CORS? 重复的“ Access-Control-Allow-Origin:*”标题会破坏CORS吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM