diff --git a/index.bs b/index.bs index bebaab3..06e337f 100644 --- a/index.bs +++ b/index.bs @@ -183,7 +183,7 @@ spec: SHA2; urlPrefix: http://csrc.nist.gov/publications/fips/fips180-4/fips-180 - * A user agent wishes to ensure that JavaScript code running in high-privilege HTML + * A user agent wishes to ensure that JavaScript code running in high-privilege HTML contexts (for example, a browser's New Tab page) aren't manipulated before display. Integrity metadata mitigates the risk that altered JavaScript will run in these pages' high-privilege contexts. @@ -199,10 +199,6 @@ spec: SHA2; urlPrefix: http://csrc.nist.gov/publications/fips/fips180-4/fips-180 The terms [=/origin=] and [=same origin=] are defined in HTML. [[!HTML]] - The representation data of a resource is defined by - Section 3 - of RFC 7231. [[!RFC7231]] - A base64 encoding is defined in Section 4 of RFC 4648. [[!RFC4648]] @@ -346,61 +342,12 @@ spec: SHA2; urlPrefix: http://csrc.nist.gov/publications/fips/fips180-4/fips-180 ## Response verification algorithms ## {#verification-algorithms} - ### Apply |algorithm| to |response| ### {#apply-algorithm-to-response} + ### Apply |algorithm| to |bytes| ### {#apply-algorithm-to-response} - 1. Let |result| be the result of [[#apply-algorithm-to-response]] - to the representation data without any content-codings - applied, except when the user agent intends to consume the content with - content-codings applied. In the latter case, let |result| be - the result of applying |algorithm| to the representation data. + 1. Let |result| be the result of applying |algorithm| to |bytes|. 2. Let |encodedResult| be result of base64 encoding |result|. 3. Return |encodedResult|. - ### Is |response| eligible for integrity validation? ### {#is-response-eligible} - - In order to mitigate an attacker's ability to read data cross-origin by - brute-forcing values via integrity checks, responses are only eligible for such - checks if they are same-origin or are the result of explicit access granted to - the loading origin via Cross Origin Resource Sharing [[!Fetch]]. - - Note: As noted in - RFC6454, section 4, - some user agents use - globally unique identifiers for each file URI. This means that - resources accessed over a `file` scheme URL are unlikely to be - eligible for integrity checks. - - Note: Being in a Secure Context (e.g., a document delivered over HTTPS) is not - necessary for the use of integrity validation. Because resource integrity is - only an application level security tool, and it does not change the security - state of the user agent, a Secure Context is unnecessary. However, if integrity - is used in something other than a Secure Context (e.g., a document delivered - over HTTP), authors are reminded that the integrity provides no security - guarantees at all. For this reason, authors are encouraged to only deliver - integrity metadata in a Secure Context. See [[#non-secure-contexts]] for - more discussion. - - The following algorithm details these restrictions: - - 1. Let |response| be the response that results from - fetching the |resource|. - 2. If the |response| type is `basic`, - `cors` or `default`, return `true`. - 3. Return `false`. - -
- The response types are defined by the Fetch - specification [[!FETCH]] and refer to the following: - - * `basic` is a same origin response, and thus the requestor has full access - to read the body. - * `cors` is a valid response to a cross-origin, CORS-enabled request, and thus - again the requestor has full access to read the body. - * `default` is a valid response that is generated by a Service Worker as a - response to the request, so its body, too, is fully readable by the requestor. - -
- ### Parse |metadata| ### {#parse-metadata} This algorithm accepts a string, and returns either `no metadata`, or a set of @@ -440,23 +387,21 @@ spec: SHA2; urlPrefix: http://csrc.nist.gov/publications/fips/fips180-4/fips-180 set, and add |item| to |result|. 3. Return |result|. - ### Does |response| match |metadataList|? ### {#does-response-match-metadatalist} +

Do |bytes| match |metadataList|?

1. Let |parsedMetadata| be the result of parsing |metadataList|. 2. If |parsedMetadata| is `no metadata`, return `true`. - 3. If |response| is not eligible for integrity - validation, return `false`. - 4. If |parsedMetadata| is the empty set, return `true`. - 5. Let |metadata| be the result of + 3. If |parsedMetadata| is the empty set, return `true`. + 4. Let |metadata| be the result of getting the strongest metadata from |parsedMetadata|. - 6. For each |item| in |metadata|: + 5. For each |item| in |metadata|: 1. Let |algorithm| be the |alg| component of |item|. 2. Let |expectedValue| be the |val| component of |item|. 3. Let |actualValue| be the result of applying |algorithm| to |response| + href="#apply-algorithm-to-response">applying |algorithm| to |bytes| . 4. If |actualValue| is a case-sensitive match for |expectedValue|, return `true`. @@ -485,12 +430,6 @@ spec: SHA2; urlPrefix: http://csrc.nist.gov/publications/fips/fips180-4/fips-180 execute correctly, even if the HTTPS version of a resource differs from the HTTP version. - Note: This algorithm returns `false` if the response is not eligible for integrity - validation since Subresource Integrity requires CORS, and it is a logical error - to attempt to use it without CORS. Additionally, user agents SHOULD report a - warning message to the developer console to explain this failure. - ## Verification of HTML document subresources ## {#verification-of-html-document-subresources} A variety of HTML elements result in requests for resources that are to be @@ -562,7 +501,7 @@ spec: SHA2; urlPrefix: http://csrc.nist.gov/publications/fips/fips180-4/fips-180 ## Handling integrity violations ## {#handling-integrity-violations} The user agent will refuse to render or execute responses that fail an integrity - check, instead returning a network error as defined in Fetch [[!FETCH]]. + check, instead returning a network error as defined in Fetch [[!Fetch]]. Note: On a failed integrity check, an `error` event is fired. Developers wishing to provide a canonical fallback resource (e.g., a resource not served diff --git a/index.html b/index.html index ff5a932..8c0562f 100644 --- a/index.html +++ b/index.html @@ -3,9 +3,1327 @@ Subresource Integrity - - + + +