CSP レポート Reporting-Endpoints ヘッダ

ブラウザで何が起こっているのかを知る Reporting API と ReportingObserver | blog.jxck.io 2020

Report-To header は Deprecated

Warning: This header has been replaced by the Reporting-Endpoints HTTP response header. It is a deprecated part of an earlier iteration of the Reporting API specification.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Report-To

https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Reporting-Endpoints

CSP 関連のレスポンスヘッダー

CSP レポートを送るためには Content-Security-Policy ないし Content-Security-Policy-Report-Only ヘッダーに専用のディレクティブを指定する必要があります。これはもともと CSP 専用の report-uri ディレクティブ(developer.mozilla.org)であったものが、CSP 以外を含めた様々なレポートに対応した Reporting API を利用するように変更され、今は report-to ディレクティブ(developer.mozilla.org)と Reporting-Endpoints ヘッダー(developer.mozilla.org)を組み合わせる方式となっています。

ChromeSafari は現行仕様に対応しているのですが、Firefox は最新の 136 Nightly においても古い report-uri ディレクティブしかサポートしていないため、実際は両方を指定する必要があります。

Content-Security-Policy: default-src 'self'; report-uri https://example.com/endpoint; report-to csp
Reporting-Endpoints: csp="https://example.com/endpoint"
なお Reporting API に対応したブラウザであっても report-uri ディレクティブのサポートを取り止めたわけではないため、たとえ report-to ディレクティブを書かなくてもレポートの送信自体は行われます。ただし report-uri ディレクティブではレポートが即時配信されるのに対し、Reporting API ではレポートのリストがいったんキューに入れられ、ブラウザが送信タイミングを制御することとされている違いがあります[1]。すなわち、とくに複数のレポートが送信される際におけるパフォーマンス向上のメリットがあるので、多少レスポンスヘッダーが長くなるにせよ最新仕様へ準拠したほうがよいでしょう。

Report URI サービスの有料化に伴い CSP レポートのエンドポイントを自作 2025