.htaccess htaccess Content-Security-Policy/CSP标头被阻止

jchrr9hc  于 2023-06-24  发布在  其他
关注(0)|答案(1)|浏览(107)

我正在尝试在.htaccess文件中设置Content-Security-Policy/CSP headers。但是,由于某种原因,它在developmentproduction环境中被阻塞。
同样的事情也发生在.css和其他来源,如图像。

Header set X-XSS-Protection "1; mode=block"
Header add Content-Security-Policy "script-src 'self' http://*.google.com https://*.google.com https://*.googleapis.com"
...

我已经试过在谷歌上搜索解决方案,但到目前为止没有运气。

fnx2tebb

fnx2tebb1#

这个问题已经解决了。
我必须使用httphttps协议定义外部资源的所有基本URL和特定路径。与self沿着允许应用程序的所有文件和unsafe-inline用于运行页面上编写的内联脚本。

<IfModule mod_headers.c>
  ...
  Header add Content-Security-Policy "\
    default-src 'self' 'unsafe-inline' https://translate.googleapis.com http://translate.googleapis.com ...; \
    style-src 'self' 'unsafe-inline' https://fonts.gstatic.com ...; \
    img-src 'self' 'unsafe-inline' https://www.google-analytics.com http://www.google-analytics.com ...; \
    font-src 'self' 'unsafe-inline' https://fonts.gstatic.com ...; \
    ...;"
</IfModule>

请注意:

1.使用unsafe-inline被认为是一种安全威胁。
1.如果您不是从同一来源请求多个文件,请尝试使用特定的URL。
我希望这能帮助有需要的人。

相关问题