以下是由Google Chrome和Apple的Safari使用的WebKit开发工具中的一个错误造成的。 我已经与CrBug做了一个错误报告 ,然后在WebKit Changeset 116952中find这个回归。 我要感谢@Grumpy和@Matthieu Cormier他们的帮助正在跟踪这一个。 我不能等待Chrome Canary的下一个版本:)。
我在我的服务器上安装了nginx和PHP-FPM,在创build一个新的网站期间,尽可能快地尝试Google Chrome的审计工具。 其中一些错误给了我这个。
Leverage proxy caching (10) The following publicly cacheable resources contain a Set-Cookie header. This security vulnerability can cause cookies to be shared by multiple users.
所以我想知道的是,为了不为这个域设置一个Set-Cookie头,我必须添加下面的语句。 然后,我会采取这些信息,并将其应用到CSS,IMG等子域,以便它可以正确caching的浏览器。
server { gzip on; gzip_static on; listen 80; server_name img.domain.tld; root /www/domain/tld; index index.php index.htm index.html; location ~* \.(gif|png|jpg|jpeg|svg)$ { expires 30d; } include php_fpm; }
跟进由Grumpy提供更多信息的请求。
这里是我为PHP FPM包含的configuration文件,用在img子域中。
PHP-FPM包括
location ~ \.php$ { fastcgi_pass unix:/tmp/php.socket; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
正如你所看到的,它只应该在地址以php文件扩展名结尾时激活。
有趣的是,我也有一个css文件,被报告为有一个集cookie的头,这是由css子域没有包含在其中的php-fpm服务…这是部分的configuration文件。
server { gzip_static on; listen 80; server_name css.domain.tld; root /www/domain/css; index index.htm index.html; location ~* \.(css)$ { expires 7d; } }
这些文件是…
Leverage proxy caching (5) The following publicly cacheable resources contain a Set-Cookie header. This security vulnerability can cause cookies to be shared by multiple users.
domain.tld服务器configuration看起来像这样。
server { gzip on; gzip_static on; listen 80; server_name .domain.tld; root /www/domain/www; index index.php index.htm index.html; location ~* \.(htm|html|ico|icns|hqx|gif|png|svg|jpg|jpeg|svg)$ { expires 1d; } include php_fpm; }
识别要caching的资源是非默认行为。 所以,无论是由Chrome引起的这个通知是你指定要caching的对象。
caching指令(在这种情况下是公共的)可以通过2种方式设置。
根据你的上面的nginxconfiguration,忽略整个include php_fpm; ,除非你的图像(gif,jpg,png)以某种方式被执行,否则没有任何东西会提示#1。
PHP也有这样的caching指令。 在这种情况下,你真的应该从核心中解决问题,而不是尝试修补工作。
但是在这两种情况下,你也可以input一个奇怪的场景。 如果你的图片没有find,它会试图find一个404页面。 如果404是一个可执行文件(php),直接或间接地,它可以携带一个设置cookie命令。 如果404指令也告诉它被caching,这将是一个不好的行为。 所以,一定要检查一下。 同样也明显适用于任何其他错误代码。
这是我所能猜到的所有现在的信息。 如果发现任何错误以及完整configurationnginx和/或php-fpm,您可能需要跟进其他信息,以确定导致Chrome发送此类消息的确切项目。
我试着查看完整的HTTP标头,看看有没有任何迹象表明cookie或传递任何自定义信息。
来自OP网站的响应标题引起警告。
telnet img.nassauems.net 80 Trying 205.186.162.66... Connected to img.nassauems.net. Escape character is '^]'. GET http://img.nassauems.net/buttons/get_adobe_reader.png HTTP/1.1 Host: img.nassauems.net HTTP/1.1 200 OK Server: nginx/1.2.4 Date: Sat, 12 Jan 2013 20:24:19 GMT Content-Type: image/png Content-Length: 2597 Last-Modified: Fri, 28 Dec 2012 08:30:57 GMT Connection: keep-alive Expires: Mon, 11 Feb 2013 20:24:19 GMT Cache-Control: max-age=2592000 Accept-Ranges: bytes
来自我的网站的示例响应标题,不会导致警告。
telnet www.mysite.com 80 Trying 123.123.123.123... Connected to www.mysite.com. Escape character is '^]'. GET http://www.mysite.com/test.png HTTP/1.1 Host: www.mysite.com HTTP/1.1 200 OK Server: nginx/1.0.12 Date: Sat, 12 Jan 2013 20:21:43 GMT Content-Type: image/png Content-Length: 207 Last-Modified: Sat, 27 Aug 2011 04:42:30 GMT Connection: keep-alive Expires: Sun, 13 Jan 2013 20:21:43 GMT Cache-Control: max-age=86400 Accept-Ranges: bytes
您看得出来差别吗? 我不能!
虽然在你的情况下,似乎你可能会在工具中发现一些错误,报告你的graphics文件包含一个Set-Cookie指令(这是不太可能的,你会有“Set-Cookie” nginx与你描述的设置),我实际上遇到了一个Java Web应用程序设置一些我不想设置的cookie的情况。
这可以通过在server上下文中放置以下指令的nginx来解决(根据需要将proxy_为fastcgi_ ):
proxy_hide_header Set-Cookie; proxy_ignore_headers Set-Cookie; # important! Remember the special inheritance rules for proxy_set_header: # http://nginx.org/ru/docs/http/ngx_http_proxy_module.html#proxy_set_header proxy_set_header Cookie "";
以上三个指令都非常重要: proxy_hide_header确保头不会被传回客户端, proxy_ignore_headers确保头不会自动禁止nginx中的caching,最后, proxy_set_header确保客户端不能将任何先前的cookie传递给webapp并破坏你的caching。 注意我关于proxy_set_headerinheritance的注释 – 你不能嵌套这个指令(必须在给定的级别定义全部或者没有)。
显然,你也必须确保你所有的web应用程序在以上述方式删除cookies之后仍然可以正常工作。 但是我直接知道,上面的方法在摆脱HTTP传递的cookies方面效果很好!
我最近注意到这一点,并且正在经历同样的事情。
我相信这是Chrome中的一个错误。
Chrome可能会检测到某些内容并输出无效的描述,或者可能只是一个普通的错误。
在OS X上使用Chrome 24.0.1312.52
在OS X上使用Safari 6.0.2(8536.26.17)