Skip to content

Commit f17c7b4

Browse files
authored
Fix script post-request check for scripts allowed by hashes (#654)
1 parent ce3752a commit f17c7b4

File tree

1 file changed

+55
-38
lines changed

1 file changed

+55
-38
lines changed

index.bs

Lines changed: 55 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3646,39 +3646,10 @@ this algorithm returns normally if compilation is allowed, and throws a
36463646
directive's <a for="directive">value</a> is "`Matches`", return
36473647
"`Allowed`".
36483648

3649-
2. Let |integrity expressions| be the set of <a>source expressions</a> in
3650-
|directive|'s <a for="directive">value</a> that match the
3651-
<a grammar>hash-source</a> grammar.
3652-
3653-
3. If |integrity expressions| is not empty:
3654-
3655-
1. Let |integrity sources| be the result of executing the algorithm
3656-
defined in [[SRI#parse-metadata]] on |request|'s
3657-
<a for="request">integrity metadata</a>. [[!SRI]]
3658-
3659-
2. If |integrity sources| is "`no metadata`" or an empty set, skip
3660-
the remaining substeps.
3661-
3662-
3. Let |bypass due to integrity match| be `true`.
3663-
3664-
4. <a for=set>For each</a> |source| of |integrity sources|:
3665-
3666-
1. If |directive|'s <a for="directive">value</a> does not
3667-
contain a <a>source expression</a> whose
3668-
<a grammar>hash-algorithm</a> is an <a>ASCII case-insensitive</a> match
3669-
for |source|'s <a grammar>hash-algorithm</a>, and whose
3670-
<a grammar>base64-value</a> is <a for="string" lt="is">identical to</a>
3671-
|source|'s `base64-value`, then set |bypass due to
3672-
integrity match| to `false`.
3673-
3674-
5. If |bypass due to integrity match| is `true`, return
3675-
"`Allowed`".
3676-
3677-
Note: Here, we verify only that the |request| contains a set of
3678-
<a for="request">integrity metadata</a> which is a subset of the
3679-
<a grammar>hash-source</a> <a>source expressions</a> specified by
3680-
|directive|. We rely on the browser's enforcement of Subresource
3681-
Integrity [[!SRI]] to block non-matching resources upon response.
3649+
2. If the result of executing
3650+
[[#match-integrity-metadata-to-source-list]] on |request|'s <a
3651+
for="request">integrity metadata</a> and this directive's <a
3652+
for="directive">value</a> is "`Matches`", return "`Allowed`".
36823653

36833654
3. If |directive|'s <a for="directive">value</a> contains a <a>source
36843655
expression</a> that is an <a>ASCII case-insensitive</a> match for
@@ -3714,12 +3685,20 @@ this algorithm returns normally if compilation is allowed, and throws a
37143685
directive's <a for="directive">value</a> is "`Matches`", return
37153686
"`Allowed`".
37163687

3717-
2. If |directive|'s <a for="directive">value</a> contains
3718-
"<a grammar>`'strict-dynamic'`</a>", and |request|'s
3719-
<a for="request">parser metadata</a> is not <a>"parser-inserted"</a>,
3720-
return "`Allowed`".
3688+
2. If the result of executing
3689+
[[#match-integrity-metadata-to-source-list]] on |request|'s <a
3690+
for="request">integrity metadata</a> and this directive's <a
3691+
for="directive">value</a> is "`Matches`", return "`Allowed`".
37213692

3722-
3. If the result of executing [[#match-response-to-source-list]] on
3693+
3. If |directive|'s <a for="directive">value</a> contains
3694+
"<a grammar>`'strict-dynamic'`</a>":
3695+
3696+
1. If |request|'s <a for="request">parser metadata</a> is not
3697+
<a>"parser-inserted"</a>, return "`Allowed`".
3698+
3699+
Otherwise, return "`Blocked`".
3700+
3701+
4. If the result of executing [[#match-response-to-source-list]] on
37233702
|response|, |request|, |directive|'s <a for="directive">value</a>,
37243703
and |policy|, is "`Does Not Match`", return "`Blocked`".
37253704

@@ -3792,6 +3771,44 @@ this algorithm returns normally if compilation is allowed, and throws a
37923771

37933772
4. Return "`Does Not Match`".
37943773

3774+
<h5 id="match-integrity-metadata-to-source-list" algorithm>
3775+
Does |integrity metadata| match |source list|?
3776+
</h5>
3777+
3778+
Given a <a for="/">request</a>'s <a for="request">integrity metadata</a>
3779+
|integrity metadata| and a <a>source list</a> |source list|, this algorithm
3780+
returns "`Matches`" if the integrity metadata matches one or more source
3781+
expressions in the list, and "`Does Not Match`" otherwise:
3782+
3783+
1. Assert: |source list| is not null.
3784+
3785+
2. Let |integrity expressions| be the set of <a>source expressions</a> in
3786+
|source list| that match the <a grammar>hash-source</a> grammar.
3787+
3788+
3. If |integrity expressions| is empty, return "`Does Not Match`".
3789+
3790+
4. Let |integrity sources| be the result of executing the algorithm defined
3791+
in [[SRI#parse-metadata]] on |integrity metadata|. [[!SRI]]
3792+
3793+
5. If |integrity sources| is "`no metadata`" or an empty set, return "`Does
3794+
Not Match`".
3795+
3796+
6. <a for=set>For each</a> |source| of |integrity sources|:
3797+
3798+
1. If |integrity expressions| does not contain a <a>source expression</a>
3799+
whose <a grammar>hash-algorithm</a> is an <a>ASCII
3800+
case-insensitive</a> match for |source|'s <a
3801+
grammar>hash-algorithm</a>, and whose <a grammar>base64-value</a> is
3802+
<a for="string" lt="is">identical to</a> |source|'s `base64-value`,
3803+
return "`Does Not Match`".
3804+
3805+
7. Return "`Matches`".
3806+
3807+
Note: Here, we verify only whether the |integrity metadata| is a non-empty
3808+
subset of the <a grammar>hash-source</a> sources in |source list|. We rely on
3809+
the browser's enforcement of Subresource Integrity [[!SRI]] to block
3810+
non-matching resources upon response.
3811+
37953812
<h5 id="match-request-to-source-list" algorithm>
37963813
Does |request| match |source list|?
37973814
</h5>

0 commit comments

Comments
 (0)