2017-09-23 85 views
0

我想使用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> 

回答

0

問題是,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'");