内容安全策略未运行.htaccess
问题描述:
我想使用Content-Security-Policy并尝试添加到我的.htaccess中。内容安全策略未运行.htaccess
问题:我用chrome插件检查是CSP正在运行但未找到。
<IfModule mod_headers.c>
Header set Content-Security-Policy "default-src 'self' *.facebook.com;frame-ancestors 'self' *.facebook.com;script-src 'strict-dynamic' 'nonce-rAnd0m123' 'unsafe-inline' http: https:;base-uri 'none';object-src 'none';"
</IfModule>
###DEFLATE###
<ifModule mod_deflate.c>
<filesMatch "\.(css|js|x?html?|php)$">
SetOutputFilter DEFLATE
</filesMatch>
</ifModule>
## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive on
ExpiresByType image/jpg "access plus 60 days"
</IfModule>
答
问题是,PHP设置标题自我,这意味着它忽略.htaccess设置。
我必须设置使用PHP的CSP:
header("Content-Security-Policy: default-src 'self' *.facebook.com;frame-ancestors 'self' *.facebook.com;script-src 'strict-dynamic' 'nonce-rAnd0m123' 'unsafe-inline' http: https:;base-uri 'none';object-src 'none'");