外部に公開しているRedmineサイト。
https://plan.io/redmine-security-scanner
で確認したところ、評価はA。
X-Content-Type-Options header not set Content sniffing may enable cross-site scripting attacks. Since your Redmine server is not properly sending the X-Content-Type-Options header, your users are vulnerable to this attack vector.
の診断が出てA+に至りませんでした。
そこで、設定を修正し、脆弱性評価をA+に引き上げます。
環境
- Ubuntu 24.04
- Apache 2.4
- Redmine 5.1
- mod_headers モジュール有効化済み
現状のセキュリティヘッダー確認
- /etc/apache2/sites-available/redmine.conf
で以下の箇所を確認。
Header always set Strict-Transport-Security "max-age=63072000"
Header set X-Content-Type-Options "nosniff"
Header always append X-Frame-Options "SAMEORIGIN"
Header set X-XSS-Protection "1; mode=block"
セキュリティヘッダーの適用方法を見直し、適切に設定されるよう修正します。
設定修正
- ファイルのバックアップ
sudo cp -pi /etc/apache2/sites-available/redmine.conf /path/to/backup/directory/redmine.conf.$(date +%Y%m%d)
※自分のRedmineサイトの設定ファイルを指定します。
任意のバックアップディレクトリを指定します。(筆者環境 /etc/apache2/old/redmine.conf.$(date +%Y%m%d)
- diffによるファイルバックアップ確認
diff -u /path/to/backup/directory/redmine.conf.$(date +%Y%m%d) /etc/apache2/sites-available/redmine.conf
差分がなければ(エラーがなければ)バックアップ成功です。
- ファイルの修正
上記のredmine.conf
を、以下の差分になるように修正します。(管理者権限が必要)
- Header set X-Content-Type-Options "nosniff"
- Header always append X-Frame-Options "SAMEORIGIN"
- Header set X-XSS-Protection "1; mode=block"
+ Header always set X-Content-Type-Options "nosniff"
+ Header always set X-Frame-Options "SAMEORIGIN"
+ Header always set X-XSS-Protection "1; mode=block"
- ファイル修正確認
diff -u /path/to/backup/directory/redmine.conf.$(date +%Y%m%d) /etc/apache2/sites-available/redmine.conf
上記の差分が出てくればOKです。
設定反映
- 構文確認
sudo apache2ctl configtest
→ Syntax OK
を確認します。
- Apacheステータス確認(反映前)
systemctl status apache2.service
→ active (running)
を確認します。
- Apache再起動
sudo systemctl restart apache2.service && echo $?
→ 成功時は 0 が出力されます。
- Apacheステータス確認(反映後)
systemctl status apache2.service
→ active (running)
を確認します。
修正確認
- curlによる確認
curl -I https://redmineサイト
以下のような表示を確認します。
X-Permitted-Cross-Domain-Policies: none
X-XSS-Protection: 1; mode=block
X-Request-Id: ***********
X-Download-Options: noopen
X-Frame-Options: SAMEORIGIN
X-Runtime: 0.615862
X-Content-Type-Options: nosniff
- 脆弱性診断サイトによる確認
https://plan.io/redmine-security-scanner
でURLを入力します。
過去の診断結果が表示されるため、『Re-Scan』をクリックして最新の診断結果を取得します。
「A+」の評価と、以下のような表示が出れば修正できています。
It looks like you are running Redmine 5.1.4. That's a version without any known security issues. Your Redmine is protected by properly configured TLS/SSL. All security relevant headers are configured properly. It appears that you have 3 or more Redmine plugins installed.