Access-Control-Allow-Origin无法按预期工作,允许所有流量

时间:2013-02-08 23:09:20

标签: security nginx http-headers csrf

我正在Access-Control-Allow-Origin中测试nginx http响应标头安全策略:

add_header Access-Control-Allow-Origin "https://google.com";

我希望我的域上的请求失败,但是它们正在运行,返回200状态代码。我确认确实设置了Access-Control-Allow-Origin响应标头:

Access-Control-Allow-Origin:https://google.com
Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection:keep-alive
Content-Encoding:gzip
Content-Type:text/html
Date:Tue, 05 Feb 2013 20:22:17 GMT
Expires:Thu, 19 Nov 1981 08:52:00 GMT
Pragma:no-cache
Server:nginx
Strict-Transport-Security:max-age=31556926
Transfer-Encoding:chunked
X-Frame-Options:DENY

请求标题显示正确的来源:

Origin:https://mydomainhere.com

知道可能导致这种情况的原因是什么?我希望请求失败。

感谢。

1 个答案:

答案 0 :(得分:0)

  • 服务器(像nginx这样的webserver)与access-control-allow-origin无关(除了设置或取消设置标志之外)。这是浏览器允许跨域Ajax(XhttpRequest)调用的方向。

  • 因此,当您将access-control-allow-origin设置为google.com时,您告诉bowser允许从您网站的页面调用google.com进行Ajax调用。

通过 - HTTP access control了解更多详情。

相关问题