JenkinsのClover pluginを利用したカバレッジレポートページにCSSが適用されない

CSS, Jenkins

この記事は最終更新日から1年以上が経過しています。

概要

Jenkinsでコードカバレッジ集計を行うClover pluginを利用した際、ブラウザによってはレポートページにCSSが適用されない。(Mac Safariで確認)

Chromeで閲覧
391-1.jpg

Safariで閲覧
391-2.jpg

原因

コンソールへ大量に出ているエラー通り

Refused to apply inline style because it violates the following Content Security Policy directive: “style-src ‘self'”.

Content Security Policy(CSP)が原因です。

CSPが何かは、自分で調べるか、徳丸大先生の会社公式ブログを参考にしてください。
弊社のホームページにContent Security Policy(CSP)を導入しました

解決方法

Jenkins公式にCSPについて説明があります。
Configuring Content Security Policy

Unfortunately, several popular, useful plugins are affected by this and lose part of their functionality unless the default rules are relaxed.

「遺憾ながら、いくつかの有用なプラグインが、デフォルトルールが緩和されない限り、一部の機能が制限される」 by Jenkins

あ、はい。

というわけで、CSPの設定を変更する。
変更は公式にあるJavadoc Pluginの設定を参考にしました。

対処その1

Jenkinsの管理 -> スクリプトコンソール から、CSP設定を変更する。

ただし、この方法だとJenkinsを再起動したらデフォルトルールに戻るので、一時的な対応にはいいが、恒久的対応には向かない。

対処その2

Java起動オプションに指定する。

before

after

この場合、セキュリティ対策として設定されているCSPの制限を緩めていいのかという問題があります。

そもそもJenkinsでXSS脆弱性の対策として、今のheaderになったようです。
Jenkins Security Advisory 2015-12-09

Stored XSS vulnerability through workspace files and archived artifacts
SECURITY-95 / CVE-2015-7536

In certain configurations, low privilege users were able to create e.g. HTML files in workspaces and archived artifacts that could result in XSS when accessed by other users. Jenkins now sends Content-Security-Policy headers that enables sandboxing and prohibits script execution by default.

が、アクセス制限のある社内ツールということで、現状はこれで妥協しました。
※ダメ人間のお手本

この記事を書いた人

金田匡貴
日本酒好きなWebエンジニアです。わりと幅広く色々やっています。

CSS, Jenkins