Skip to content

Commit c3bff81

Browse files
author
Francois Marier
committed
SRI: re-introduce the distinction between empty and invalid metadata
This commit reintroduces a distinction that used to exist in the spec prior to 930ec20 (see #86 and #119). As [discussed on the list](https://lists.w3.org/Archives/Public/public-webappsec/2015Aug/0006.html), it helps developers catch mistakes by failing closed on CORS errors when the `integrity` attribute is non-empty (an indication that the developer meant to use SRI). Prior to this commit, `integrity` attributes which consists of only invalid metadata would fail open (silently load).
1 parent 3da32cb commit c3bff81

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

specs/subresourceintegrity/spec.markdown

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -372,16 +372,18 @@ valid hash expressions whose hash functions are understood by
372372
the user agent.
373373

374374
1. Let <var>result</var> be the empty set.
375-
2. For each <var>token</var> returned by [splitting <var>metadata</var> on
375+
2. Let <var>empty</var> be equal to `true`.
376+
3. For each <var>token</var> returned by [splitting <var>metadata</var> on
376377
spaces][split-on-spaces]:
377-
1. If <var>token</var> is not a valid metadata, skip the remaining
378+
1. Set <var>empty</var> to `false`.
379+
2. If <var>token</var> is not a valid metadata, skip the remaining
378380
steps, and proceed to the next token.
379-
2. Parse <var>token</var> per the grammar in [integrity metadata][]
380-
3. Let <var>algorithm</var> be the <var>alg</var> component of
381+
3. Parse <var>token</var> per the grammar in [integrity metadata][]
382+
4. Let <var>algorithm</var> be the <var>alg</var> component of
381383
<var>token</var>.
382-
4. If <var>algorithm</var> is a hash function recognized by the user
384+
5. If <var>algorithm</var> is a hash function recognized by the user
383385
agent, add the parsed <var>token</var> to <var>result</var>.
384-
3. Return `no metadata` if <var>result</var> is empty, otherwise return
386+
4. Return `no metadata` if <var>empty</var> is `true`, otherwise return
385387
<var>result</var>.
386388

387389
[split-on-spaces]: http://www.w3.org/TR/html5/infrastructure.html#split-a-string-on-spaces
@@ -420,9 +422,10 @@ the user agent.
420422
2. If <var>parsedMetadata</var> is `no metadata`, return `true`.
421423
3. If [<var>response</var> is not eligible for integrity
422424
validation][eligible], return `false`.
423-
4. Let <var>metadata</var> be the result of [getting the strongest
425+
4. If <var>parsedMetadata</var> is the empty set, return `true`.
426+
5. Let <var>metadata</var> be the result of [getting the strongest
424427
metadata from <var>parsedMetadata</var>][get-the-strongest].
425-
5. For each <var>item</var> in <var>metadata</var>:
428+
6. For each <var>item</var> in <var>metadata</var>:
426429
1. Let <var>algorithm</var> be the <var>alg</var> component of
427430
<var>item</var>.
428431
2. Let <var>expectedValue</var> be the <var>val</var> component of
@@ -431,7 +434,7 @@ the user agent.
431434
<var>algorithm</var> to <var>response</var>][apply-algorithm].
432435
4. If <var>actualValue</var> is a case-sensitive match for
433436
<var>expectedValue</var>, return `true`.
434-
6. Return `false`.
437+
7. Return `false`.
435438

436439
This algorithm allows the user agent to accept multiple, valid strong hash
437440
functions. For example, a developer might write a `script` element such as:

0 commit comments

Comments
 (0)