Movatterモバイル変換


[0]ホーム

URL:


  1. 開発者向けのウェブ技術
  2. HTTP
  3. リファレンス
  4. ヘッダー
  5. Content-Security-Policy
  6. CSP: report-to

このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docsコミュニティーについてもっと知り、仲間になるにはこちらから。

View in EnglishAlways switch to English

CSP: report-to

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Content-Security-Policyreport-to ディレクティブは、 CSP 違反の報告に使用するエンドポイントの名前を示します。

CSP 違反が発生した場合、シリアライズされたCSPViolationReportBody オブジェクトのインスタンスが含まれているレポートが生成されます。このレポートは、レポート API で定義されている一般的なメカニズムを使用して、エンドポイント名に対応する URL に送信されます。

サーバーは、 HTTP のReporting-Endpoints レスポンスヘッダーに、エンドポイント名とそれに対応する URL の間の対応付けを別個に指定する必要があります。

CSP バージョン1
ディレクティブ種別報告ディレクティブ
このディレクティブは<meta> 要素では対応していません。

構文

http
Content-Security-Policy: …; report-to <endpoint_name>

<endpoint_name> は、 HTTP のReporting-Endpoints レスポンスヘッダーで指定されたエンドポイントの名前です。また、Report-To非推奨; レスポンスヘッダーでサーバーが指定したグループの名前である場合もあります。

違反レポートの構文

CSP 違反レポートは、JSON 形式のReport オブジェクトのインスタンスであり、type プロパティに"csp-violation" という値が存在し、本体はCSPViolationReportBody オブジェクトをシリアライズした形式です(各オブジェクトのプロパティ定義については、それぞれのオブジェクトを参照してください)。レポートは、Content-Typeapplication/reports+json であるPOST 操作により、ターゲットエンドポイントに送信されます。

単一のレポートのJSONは、次のようになるでしょう。

json
{  "age": 53531,  "body": {    "blockedURL": "inline",    "columnNumber": 39,    "disposition": "enforce",    "documentURL": "https://example.com/csp-report",    "effectiveDirective": "script-src-elem",    "lineNumber": 121,    "originalPolicy": "default-src 'self'; report-to csp-endpoint-name",    "referrer": "https://www.google.com/",    "sample": "console.log(\"lo\")",    "sourceFile": "https://example.com/csp-report",    "statusCode": 200  },  "type": "csp-violation",  "url": "https://example.com/csp-report",  "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36"}

使用上のメモ

report-to ディレクティブはreport-uri を置き換えることを意図しており、report-to に対応しているブラウザーはreport-uri ディレクティブを無視します。しかし、report-to が広く対応されるまでは、どちらのディレクティブも表示させるように指定することができます。

http
Content-Security-Policy: …; report-uri https://endpoint.example.com; report-to endpoint_name

なお、このトピックの他の例ではreport-uri を示していません。

CSP 違反レポートのエンドポイントの設定

サーバーは、 HTTP レスポンスのReporting-Endpoints ヘッダーを使用して、エンドポイント名と URL の割り当てられた対応を定義することができます。任意の名前を使用することができます。ここでは、name-of-endpoint という名前を選んでいます。

http
Reporting-Endpoints: name-of-endpoint="https://example.com/csp-reports"

サーバーは、report-to ディレクティブを使用する際に、 CSP 違反レポートの送信対象としてこのエンドポイント名を設定することができます。

http
Content-Security-Policy: default-src 'self'; report-to name-of-endpoint

仕様書

Specification
Content Security Policy Level 3
# directive-report-to

ブラウザーの互換性

関連情報

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2026 Movatter.jp