(參考:https://imququ.com/post/web-security-and-response-header.html#toc-0)
Content-Security-Policy
- 只允許本站資源:
Content-Security-Policy: default-src ‘self’
- 允許本站的資源以及任意位置的圖片以及http://trustedscripts.example.com 下的腳本:
Content-Security-Policy: default-src ‘self’; img-src *; script-src http://trustedscripts.example.com
secure/HttpOnly cookie
- secure屬性
當設置為true時,表示創建的 Cookie 會被以安全的形式向服務器傳輸,也就是只能在 HTTPS 連接中被瀏覽器傳遞到服務器端進行會話驗證,如果是 HTTP 連接則不會傳遞該信息,所以不會被竊取到Cookie 的具體內容。 - HttpOnly屬性
如果在Cookie中設置了"HttpOnly"屬性,那么通過程序(JS腳本、Applet等)將無法讀取到Cookie信息,這樣能有效的防止XSS攻擊。
X-XSS-Protection: 1; mode=block
指定 1 為開啟瀏覽器 XSS 防御機制。
指定 mode=block 為當瀏覽器檢測到 XSS 攻擊是不再渲染頁面。