
Content Security Policy中使用Google Analytics
防範XSS攻擊
CSP是由Google提出的安全性工具,主要是因為多年來網站很容易受到Cross-site Scripting XXS攻擊。
完全封鎖
首先是試一試最安全的設定,根據CSP Evaluator的設定如下
script-src 'strict-dynamic' 'nonce-rAnd0m123' 'unsafe-inline' http: https:;
object-src 'none';
base-uri 'none';
report-uri https://csp.example.com;
這個設定下....幾乎什麼script也不可能運作!連本地的script也被封死了...
default-src 'self' https://*.google.com https://*.googleapis.com https://www.google-analytics.com https://*.gstatic.com;
不過我需要Google Analytics,因為Google Analytics需要多個source,所以我了defau