Content-Security-Policy-Report-Only ヘッダー
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2016年8月.
HTTP の Content-Security-Policy-Report-Only レスポンスヘッダーは、セキュリティポリシーを強制することなく、コンテンツセキュリティポリシー (CSP) 違反とその効果を監視するのに役立ちます。
このヘッダーを使用することで、特定の Content-Security-Policy が適用・強制される前に、違反を検査または修復することができます。
レポートを送信するには、CSP report-to ディレクティブを指定する必要があります。指定しない場合、操作は一切効果がありません。
違反レポートは、レポート API を使用して、HTTP の Reporting-Endpoints レスポンスヘッダーで定義され、CSP の report-to ディレクティブで選択されたエンドポイントに送信されます。
詳細については、コンテンツセキュリティポリシー (CSP) のこの記事も参照してください。
メモ:
このヘッダーは非推奨となった report-uri ディレクティブ(report-to で置き換えられつつある)でも使用することができます。
使用方法と結果のレポート構文は若干異なります。詳細は report-uri のトピックを参照してください。
構文
Content-Security-Policy-Report-Only: <policy-directive>; …; <policy-directive>; report-to <endpoint-name>
ディレクティブ
Content-Security-Policy-Report-Only ヘッダーはすべての Content-Security-Policy ディレクティブに対応していますが、sandbox を除き、これは無視されます。
メモ:
CSP の report-to ディレクティブをこのヘッダーと共に使用しないと、効果がありません。
例
>Content-Security-Policy-Report-Only を使用して CSP レポートを送る
report-to ディレクティブを使用するには、まず Reporting-Endpoints レスポンスヘッダーを使用して対応するエンドポイントを定義する必要があります。
下記の実例では、csp-endpoint という単一のエンドポイントを定義しています。
Reporting-Endpoints: csp-endpoint="https://example.com/csp-reports"
次に、report-to および report-uri を使用してレポートの出力先を定義できます。
次に示すように、この具体的なレポートは、ページがリソースを安全でない方法で読み込んだ場合、またはインラインコードから読み込んだ場合に報告されます。
Content-Security-Policy-Report-Only: default-src https:;
report-uri /csp-report-url/;
report-to csp-endpoint;
メモ:
report-to ディレクティブは非推奨の report-uri よりも推奨されますが、report-to はまだブラウザー間で完全に対応されていないため、両方を宣言しています。
仕様書
| Specification |
|---|
| Content Security Policy Level 3> # cspro-header> |
ブラウザーの互換性
関連情報
Content-Security-Policy- CSP の
report-toディレクティブ - CSP の
report-uriディレクティブ 非推奨;