本次的ZAP掃出以下的中風險
去年已經出現 本來想說去年應該已經解決了
但今年還是看到 可能是解決不完整
先在 apache 的 CSP 設定內加入以下二行
frame-ancestors 'self';
form-action 'self';
再來處理 style-src
先把 'unsafe-inline' 拿掉
接下來處理的方式有二種
如果在html檔裡直接定義 css
要使用 hash 或 nonce
使用 nonce 是比較方便的做法
首先在 apache config 裡
style-src 這個定義加上 'nonce-12345678'
12345678 建議置換為亂碼
之後在 css 定義裡加上 nonce 定義
nonce的字串必須跟apahce config裡的相同
<style nonce="123456789" type="text/css">
</style>
修改 html內文 把原本直接定義的style改成先定義css再引用
例如原本是
<a href="123456.exe" style="color:red;">123456</a>
要改成
<a href="123456.exe" class="red-text">123456</a><br>
同時在上方的css定義加入 red-text
<style nonce="sjdfhs6849" type="text/css">
.red-text {
color: red;
font-size: 21px;
}
</style>
另外不使用 hash 跟 nonce 的方法是 把css以獨立檔案定義後再引用
建立 style.css
檔案內容如下
.red-text {
color: red;
font-size: 21px;
}
接下來在 html 的head中引用
<head>
<link rel="stylesheet" href="style.css">
</head>
html內文的修正方法如上