content-security-policy - 内容安全策略指令:“default-src 'self'”。请注意,'frame-src' 没有明确设置,所以 'default-src' 用作后备
问题描述
注销后,我使用 WsFedration(ADFS) 在我们的应用程序中集成了单点登录,它在成功注销并返回登录页面时重定向到页面。在 Windows 服务器中托管后,此操作正常,但在托管后,到 Nginx 服务器我遇到问题,它没有重定向到登录页面,控制台错误说,
拒绝框架“https://xxx-yyy.zzz.rr/”,因为它违反了以下内容安全策略指令:“default-src 'self'”。请注意,'frame-src' 没有明确设置,所以 'default-src' 用作后备
然后我对此进行搜索并将内容安全策略(CSP)添加到 Nginx 配置文件中,如下所示。
add_header X-Content-Type-Options "nosniff" always;
add_header X-Frame-Options SAMEORIGIN always;
add_header X-XSS-Protection "1; mode=block" always;
add_header Content-Security-Policy "style-src-elem 'unsafe-inline' 'self' https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-glyphicons.css https://fonts.googleapis.com/css";
add_header Content-Security-Policy "style-src 'unsafe-inline' 'self' https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-glyphicons.css https://fonts.googleapis.com/css";
add_header Content-Security-Policy "frame-src 'unsafe-inline' 'self' none";
add_header Content-Security-Policy "default-src 'unsafe-inline' 'self'; https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-glyphicons.css https://fonts.googleapis.com/css ";
add_header Content-Security-Policy "frame-ancestors 'self' 'unsafe-inline' none";
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
add_header Content-Security-Policy "font-src 'self' 'unsafe-inline' https://netdna.bootstrapcdn.com https://fonts.gstatic.com";
我尝试了几种方法,但我无法弄清楚,如果有人可以帮助我解决这个问题,非常感谢。提前致谢。
解决方案
- 您同时发布多个 CSP,它们的工作方式与您想象的不同。如果发布了多个 CSP,则将它们与逻辑“AND”组合。
但是您在每个 CSP 中巧妙地使用了独特的指令,因此如果不是该指令,整个集合将按预期工作default-src
。如果它在单独的 CSP 中发布,则default-src
覆盖所有其他后备指令。结果,您'unsafe-inline' 'self'
对所有指令都有规则。
您必须将所有指令放在一个add_header Content-Security-Policy
.
- 您在规则中有一些错误,例如:
https://fonts.googleapis.com/css
source 应该有尾随/
,因为它是文件夹名,而不是文件名。none
token 应该是单引号 -'none'
,如果它与其他来源结合,它将被忽略。"frame-src 'unsafe-inline' 'self' none"
-frame-src
不支持'unsafe-inline'
令牌。"frame-ancestors 'self' 'unsafe-inline' none"
-frame-ancestors
不支持'unsafe-inline'
令牌。"font-src 'self' 'unsafe-inline' https://netdna.bootstrapcdn.com https://fonts.gstatic.com"
-font-src
不支持'unsafe-inline'
令牌。"default-src 'unsafe-inline' 'self'; https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-glyphicons.css https://fonts.googleapis.com/css "
-;
后面的(分号)'self'
确实完成了default-src
规则集,因此https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-glyphicons.css
算作指令名称。
这里是你的规则:
add_header Content-Security-Policy " \
default-src 'self' 'unsafe-inline' https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-glyphicons.css https://fonts.googleapis.com/css/; \
font-src 'self' https://netdna.bootstrapcdn.com https://fonts.gstatic.com; \
frame-ancestors 'self'; \
frame-src 'self'; \
style-src 'self' 'unsafe-inline' https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-glyphicons.css https://fonts.googleapis.com/css/; \
style-src-elem 'self' 'unsafe-inline' https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-glyphicons.css https://fonts.googleapis.com/css/; \
"
推荐阅读
- java - 使用 vetx-config 异步加载配置文件
- nginx - nginx 是否需要 $http_x_forwarded_for 标头的 set_real_ip_from 指令?
- docker - Docker Swarm 上的 Hadoop 集群 - Datanodes 无法连接到 Namenode
- colors - gnuplot:如何在烛台中设置晶须的颜色?
- r - R总结与DataTable
- c++ - MT166-С 连接无响应。С++ 库
- javascript - 在数组中打印对象
- android - 无法将数据写入 Firebase 实时数据库 | 安卓工作室
- javascript - 在 nashorn 中将 html 解码的字符串转换为人类可读的字符串
- javascript - 两个星期之间的日期名称缩写js