apache - Apache CSP 设置
问题描述
我有一个像反向代理一样的 apache 2.4。在将用户代理到目标服务器之前,我使用简单的表单登录来验证用户身份。
登录页面非常简单:
<!doctype html>
<html lang="it">
<head><title>AUTENTICAZIONE</title>
</head>
<body>
<script type="text/javascript">
</script>
<form method="POST" action="/dologin2.html">
Username: <input type="text" name="httpd_username" value="" />
Password: <input type="password" name="httpd_password" value="" />
<input type="submit" name="login" value="Login" />
<input type="hidden" name="httpd_location" value="https://sgsvrsiimws11lx.sistemi.group/primoacc/sigma/app" />
</form>
</body>
</html>
我在这个页面上遇到了 Firefox 和 chrome 的问题:
拒绝执行内联脚本,因为它违反了以下内容安全策略指令:“default-src 'self'”。启用内联执行需要“unsafe-inline”关键字、哈希(“sha256-AbpHGcgLb+kRsJGnwFEktk7uzpZOCcBY74+YBdrKVGs=”)或随机数(“nonce-...”)。另请注意,'script-src' 未明确设置,因此 'default-src' 用作后备。
在我的 httpd.conf 我已经设置了这个:
标头集 Content-Security-Policy "frame-ancestors 'unsafe-inline' 'self' sgsvrsiimws11lx.sistemi.group;"
我已经设置了它,因为后端的一些角度对象没有加载。
我尝试以多种方式设置 Content-Security-Policy,但登录页面中的 javascript 始终出现错误。
即使我有那个错误我也可以用chrome登录,用firefox没有。
如何在 apache 中正确设置 Content-Security-Policy 标头以与我的登录页面正常工作?
谢谢
解决方案
Header set Content-Security-Policy "frame-ancestors 'unsafe-inline' 'self' sgsvrsiimws11lx.sistemi.group;"
不限制内联脚本的执行。
您可以删除'unsafe-inline'
令牌,因为frame-ancestors
指令不支持它。
看起来您的“目标服务器”发送了一个登录页面,其中包含有自己的内容安全策略default-src 'self'
规则。
在开发工具中检查您在浏览器中真正拥有的 CSP 标头,这里是教程。
如果您的“目标服务器”发布了自己的 CSP,则必须添加'unsafe-inline'
到其中,而不是添加到反向代理配置中。'unsafe-inline'
应将令牌插入script-src
指令中(或者如果default-src
不script-src
使用)。
注意:我希望您知道这'unsafe-inline'
会降低 CSP 保护的能力。您可以使用'nonce-value'
或'sha256-AbpHGcgLb+kRsJGnwFEktk7uzpZOCcBY74+YBdrKVGs='
(取自 Chrome 的警告)来安全地允许内联脚本。
推荐阅读
- google-cloud-platform - 如何在签名 URL 中加密/隐藏谷歌云存储桶名称
- javascript - 如何在Javascript中制作精确的睡眠功能,可能使用承诺?
- django - Django Custom 中间件不在每个页面中显示消息
- svelte - 无法使用 wavesurfer 读取 null 的属性“持续时间”
- android - 如何在类控制器之间同步包含 AsyncTask 和片段
- r - 无法将 x 比例从日期更改为数字
- mysql - 使用 Mysql DENSE_RANK() 函数从一些详细信息(id、主题、点)更改表以添加额外的列(排名)
- java - java.lang.string 类型的连接值无法转换为 jsonobject [Android Volley 库]
- odoo - 如何在odoo中添加自定义选择字段颜色
- c - 数组类型究竟是如何存储在 C 中的?