【发布时间】:2019-07-21 16:49:21
【问题描述】:
我有一个包含用户面板的 PHP 脚本。在这个用户面板中,有一些信息,例如他们的详细信息、帐户余额、分配给他们帐户的项目。
偶尔浏览用户面板时,您会随机看到另一个用户帐户页面,但刷新后会返回您的页面。
我最初认为发生了某种 PHP 会话损坏,但我开始记录所有请求(请求者的 IP + 用户 ID)。由此,我能够确定当另一个用户帐户页面被随机/意外提供时,PHP 永远不会执行。 (我的 IP 中从来没有出现过“随机”帐户的日志条目)
该网站使用 cloudflare,虽然我添加了一个页面规则来禁用整个客户区的缓存。
我已经为客户区的每个请求添加了这个输出:
session_cache_limiter('private_no_expire:');
header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Pragma: no-cache"); // HTTP/1.0
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
在我的 htaccess 文件中,我使用 mod_expires 和以下内容:
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresByType text/html "access 0 seconds"
ExpiresDefault "access 1 month"
</IfModule>
此时我完全不知道我还能做些什么来阻止 ISP/Cloudflare 提供缓存版本。
有没有人知道什么可能导致我的用户面板页面的缓存版本显示给用户?
发生这种情况的响应标头如下。
HTTP/2.0 200 OK
date: Wed, 27 Feb 2019 21:03:30 GMT
content-type: text/html; charset=UTF-8
vary: Accept-Encoding
cache-control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
expires: Sat, 26 Jul 1997 05:00:00 GMT
pragma: no-cache
last-modified: Wed, 27 Feb 2019 21:03:29 GMT
vary: Accept-Encoding
x-xss-protection: 1; mode=block
x-content-type-options: nosniff
x-nginx-cache-status: HIT
x-server-powered-by: Engintron
expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
server: cloudflare
cf-ray: 4afd99361e6e3b14-YVR
content-encoding: br
X-Firefox-Spdy: h2
【问题讨论】:
-
网址一样吗?如果您使用会话来传递用户 ID(这是一件好事),那么它们可能是,如果您将每个用户的标识符(例如唯一哈希)添加到 URL,那么它可能不会将它们缓存为整体,因为它将它们视为不同的请求。即使这根本没有在 PHP 中使用。这不一定能解决您的安全问题(我个人不会缓存它)但是......只是想我会提到它。
-
@ArtisticPhoenix 我确实使用会话来传递用户 ID,并且所有 url 都是相同的。我认为这也可以,但希望避免在我的网址中添加不必要的标识符。
-
此外,它并没有真正提供任何安全性,因为即使使用模糊的标识符,仍然有人可以暴力破解缓存的页面。对于敏感信息,仅仅保护它是不够的。老实说,我不使用任何缓存,但我做了大量的后端工作。
标签: php .htaccess caching http-headers cloudflare