IIS 自定义 header "Content-Security-Policy" 被覆盖

IIS custom header "Content-Security-Policy" is overwritten

我目前遇到一个 SharePoint 网络应用程序问题,其中所有网站 return 响应 header content-security-policy: default-src 'self'; object-src 'none'; form-action 'self',这会破坏使用 Chrome 或 Firefox 的网站视图,因为样式不会被应用并且 Javascript 不会被执行。

Console-Log

Refused to execute inline script because it violates the following Content Security Policy directive: default-src 'self'.
Either the 'unsafe-inline' keyword, a hash ('sha256-WFRyoBrQbrYtLpGIdyBszDzxQni3b0V/wUirab0OhKM='), or a nonce ('nonce-...') is required to enable inline execution.
Note also that 'script-src' was not explicitly set, so 'default-src' is used as a fallback.

仅当网站使用 HTTPS 寻址时才会出现问题。我已经检查了 IIS 中的 HTTP 响应 Headers。 content-security-policy 未指定。如果我自己添加它,它会被覆盖并且不会在响应中发送 header。只安装了两个解决方案,不会混淆响应 headers.

有没有人知道还有什么可以更改自定义响应 header 并覆盖 web.config 中定义的响应?或者有其他方法可以更改 Content-Security-Policy?

我测试了通过配置 web.config 中的 "CustomHeaders" 部分来更改 IIS 响应 Headers,通过编写自定义 IIS 模块,修改了 headers 使用请求生命周期,以及使用 URL 重写工具编写额外的规则。没有任何效果...

最后我们发现有人扩展了防火墙,之后会添加新的 header 并覆盖我对 HTTPS 响应的更改。谜团解开了:)

就我而言,网络和信息安全团队要求我添加 Content-Security-Policy:default-src 'self'; header 在我的 IIS 8.5 SharePoint Server 2016 发布网站中影响所有系统页面并且浏览器拒绝执行脚本并且在控制台中我们收到此错误

拒绝执行内联脚本,因为它违反了以下内容安全策略指令:“default-src 'self'”。启用内联执行需要 'unsafe-inline' 关键字、散列 ('sha256-HU8dCwZsqh4m8QG0y6qanyzPx1d6YSGHuAN0QXmxZvw=') 或随机数 ('nonce-...')。另请注意 'script-src' 未明确设置,因此 'default-src' 用作后备。

然后我将 header 更改为 Content-Security-Policy:frame-ancestors 'self'; 并解决了问题。

我实际上是从 JohnC's Answer that helps me resolving the issue

那里得到的