Security/Subresource Integrity

The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Description

Subresource Integrity is a mechanism by which user agents may verify that a fetched resource has been delivered without unexpected manipulation. It landed in Firefox 43.

Engineering

The bulk of the code lives in these two classes:

which hook into:

Both of these hooks work in the same way:

  1. We start by creating an SRIMetadata object from the content of the integrity attribute as we process the element:
  2. We then wait until the file is downloaded and check that the hash of the contents matches the SRI hash:
  3. We return NS_ERROR_SRI_CORRUPT, which fails the load and triggers the error event on that element, if the hashes don't match.

QA

The automated tests live in these two places:

To turn on debugging output, export the following environment variable:

MOZ_LOG="SRI:5,SRIMetadata:5"

Evangelism

Documentation