在哪里声明内容安全策略report-uri?

Where to declare content security policy report-uri?

我是 Content-Security-Policy 的新手,第一次尝试在我的 Web 应用程序中实施 CSP,但我不知道在哪里放置/声明 report-uri,因为它无法声明使用元 http-equiv.

我试过将此代码放在我的 .htaccess 文件的最顶行,但它似乎没有 运行 URI。

Header set Content-Security-Policy "report-uri http://localhost/my-webapp-name/report-parser.php"

但如果我 POST 手动将某些内容添加到 'report-parser.php',脚本就可以正常工作。

更新: 看来我找到了问题,但仍未找到解决方案。我理解的问题是我在 .htaccess 上设置的策略被我在 html <head></head> 中使用元 http-equiv 声明的策略覆盖。

所以问题就变成了,在哪里声明策略 report-uri 以便它不会被 html 头部中的其他策略覆盖?

到目前为止,基于 Dipak cahvda 共享的 link https://gist.github.com/phpdave/24d879514e7411047267 的工作解决方案是将所有策略放在 php header() 函数中。