docs.rodeo

MDN Web Docs mirror

Integrity-Policy header

{{SeeCompatTable}} 

The HTTP Integrity-Policy response header allows website administrators to ensure that all resources the user agent loads (of a certain type) have Subresource Integrity guarantees.

When set the user agent will block requests on specified request destinations that omit integrity metadata, and will also block requests in no-cors mode from ever being made.

Violation reports may also be sent to if the header includes a reporting endpoint name that matches an endpoint declared using the {{HTTPHeader("Reporting-Endpoints")}}  header. Reports are generated using the Reporting API, and may also be observed in the page for which the integrity policy is being enforced, using a ReportingObserver. The format of the report body is given by the {{domxref("IntegrityViolationReportBody")}}  dictionary (a JSON-serialized form of this body is sent in POSTs to reporting server endpoints).

This helps guard against content manipulation of fetched subresources.

Header type `{{Glossary("Response header")}}` 
`{{Glossary("Forbidden request header")}}`  no

Syntax

Integrity-Policy: blocked-destinations=(<destination>),sources=(<source>),endpoints=(<endpoint>)

The header values are defined as structured field dictionaries with the following keys:

Examples

Blocking and reporting when scripts lack integrity metadata

This example shows a document that blocks and reports when any {{htmlelement("script")}}  (or HTMLScriptElement) does not specify an integrity attribute, or when a script resource is requested in no-cors mode.

Note that the integrity-endpoint used in Integrity-Policy is defined in the {{httpheader("Reporting-Endpoints")}}  header.

Reporting-Endpoints: integrity-endpoint="https://example.com/integrity", backup-integrity-endpoint="https://report-provider.example/integrity"
Integrity-Policy: blocked-destinations=(script), endpoints=(integrity-endpoint backup-integrity-endpoint)

The report payload might look like this.

{
  "type": "integrity-violation",
  "url": "https://example.com",
  "body": {
    "documentURL": "https://example.com",
    "blockedURL": "https://example.com/main.js",
    "destination": "script",
    "reportOnly": false
  }
}

Specifications

{{Specifications}} 

Browser compatibility

{{Compat}} 

See also

In this article

View on MDN