php - Chrome 和 Firefox 阻止下载动态创建的 zip 文件,称这是不寻常的下载并且可能有害
问题描述
Google Chrome 和 Mozilla Firefox 将我的 zip 文件归类为可能有害。
我写了一些代码(PHP,Codeigniter),它动态地创建了一个 zip 文件,让用户立即下载它。这种代码和平只有在用户登录后才能访问。在 localhost 上一切正常,但在生产环境中,Google Chrome 和 Mozilla firefox 将 zip 文件归类为可能有害。
产品使用 RapidSSL 的域验证证书进行 HTTPS 加密。
我做了一些研究,发现:
- 由于 zip 是二进制文件,而且网站本身知名度不高,所以下载一般被归类为不可信。
- 如果它是可通过公共 URL 访问的静态文件,Google 迟早会对其进行检查,然后将其归类为安全文件。由于这些是动态创建的 ZIP 文件,只能在登录区域访问,因此该选项不再可用。
- 可能是 SSL 证书不够安全,因为它仅经过域验证。在我在这里买一个更贵的之前,我想听听你对这个可能的解决方案的看法。更好的证书会确保 Zip 文件被认为是安全的吗?
- Google Search Console 中没有我的软件。那能做点什么吗?
- 在我的研究中,我遇到了 http 标头“内容安全策略”。设置此标头是解决方案吗?
我尝试了 codeigniter zip 库和 PHP 的 ZipArchive。两种解决方案都有同样的问题。在使用 PHP 的 ZipArchive 创建 zip 文件后,我为下载设置的标题如下:
//Set the Content-Type, Content-Disposition and Content-Length headers.
header("Content-Type: application/zip");
header("Content-Disposition: attachment; filename=$zip_name");
header("Content-Length: " . filesize($zip_path_and_filename));
//Read the file data and exit the script.
readfile($zip_path_and_filename);
exit;
我希望下载 zip 文件时不会将其归类为潜在有害文件。事实上,Microsoft Edge 并没有抱怨什么。