【问题标题】:Content Security Policy directive: "default-src 'self'". Note that 'frame-src' was not explicitly set, so 'default-src' is used as a fallback内容安全策略指令:“default-src 'self'”。请注意,'frame-src' 没有明确设置,所以 'default-src' 用作后备
【发布时间】:2021-02-02 07:57:55
【问题描述】:

我已经使用 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";    

我尝试了几种方法,但我无法弄清楚,如果有人可以帮助我解决这个问题,非常感谢。 提前致谢。

【问题讨论】:

    标签: content-security-policy


    【解决方案1】:
    1. 您同时发布了多个 CSP,它们的工作方式与您想象的不同。如果发布了多个 CSP,则将它们与逻辑“AND”组合。
      但是您在每个 CSP 中巧妙地使用 unique 指令,因此如果不是 default-src 指令,整个集合将按预期工作。如果它在单独的 CSP 中发布,default-src 将覆盖所有其他后备指令。因此,您对所有指令都有'unsafe-inline' 'self' 规则。

    您必须将所有指令放在add_header Content-Security-Policy 中。

    1. 规则中有一些errors,例如:
    • https://fonts.googleapis.com/css 源应该有尾随 /,因为它是文件夹名,而不是文件名。
    • none 令牌应该是单引号 - '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/; \
    "
    

    【讨论】:

    • 谢谢你的解释,如果我按照你说的添加,我无法重启Nginx,它说最终出现错误
    • 删除反斜杠并将所有内容拉到一行中。虽然nginx应该懂backslashes as line breaks.
    猜你喜欢
    • 1970-01-01
    • 2017-03-09
    • 2018-12-25
    • 2015-11-16
    • 2018-01-04
    • 2018-11-06
    • 1970-01-01
    • 1970-01-01
    • 2017-03-14
    相关资源
    最近更新 更多