Skip to content

Commit 7cd7668

Browse files
committed
Include imported scripts to byte-check
This changes the behavior of the service worker script resource comparison. Before this, only the main service worker script was compared to a new version. With this change, all the imported scripts stored in the imported scripts map as well as the main script are inspected against the corresponding network resources (based on the urls.) Note: - Service worker's script resource map has been renamed and moved to service worker's script resource's imported scritps map. - registration's last update check time's always updated whenever the response is fetched from the network (regardless it's a main script or an imported script.) Fixes #839.
1 parent 7deb238 commit 7cd7668

File tree

4 files changed

+529
-281
lines changed

4 files changed

+529
-281
lines changed

docs/index.bs

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
156156

157157
A <a>script resource</a> has an associated <dfn export for="script resource" id="dfn-referrer-policy">referrer policy</dfn> (a [=/referrer policy=]). It is initially the empty string.
158158

159-
A [=/service worker=] has an associated <dfn export id="dfn-script-resource-map">script resource map</dfn> which is an <a>ordered map</a> where the keys are [=/URLs=] and the values are [=/responses=].
159+
A [=script resource=] has an associated <dfn export for="script resource" id="dfn-script-resource-map">imported scripts map</dfn> which is an <a>ordered map</a> where the keys are [=/URLs=] and the values are [=/responses=].
160160

161161
A [=/service worker=] has an associated <dfn export id="dfn-skip-waiting-flag">skip waiting flag</dfn>. Unless stated otherwise it is unset.
162162

@@ -2159,10 +2159,10 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
21592159
1. Let |response| be the result of <a lt="fetch">fetching</a> |request|.
21602160
1. If |response|’s <a for="response" href="https://github.com/whatwg/fetch/issues/376">cache state</a> is not "<code>local</code>", set |registration|’s [=service worker registration/last update check time=] to the current time.
21612161
1. If |response|'s <a>unsafe response</a>'s [=response/type=] is not "<code>error</code>", and |response|'s [=response/status=] is an <a>ok status</a>, then:
2162-
1. [=map/Set=] <a>script resource map</a>[|request|'s [=request/url=]] to |response|
2162+
1. [=map/Set=] |serviceWorker|'s [=script resource=]'s [=script resource/imported scripts map=][|request|'s [=request/url=]] to |response|.
21632163
1. Return |response|.
21642164
1. Else:
2165-
1. If <a>script resource map</a>[|url|] [=map/exists=], return <a>script resource map</a>[|url|].
2165+
1. If |serviceWorker|'s [=script resource=]'s [=script resource/imported scripts map=][|url|] [=map/exists=], return |serviceWorker|'s [=script resource=]'s [=script resource/imported scripts map=][|url|].
21662166
1. Else, return a <a>network error</a>.
21672167
</section>
21682168
</section>
@@ -2190,7 +2190,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
21902190
<section>
21912191
<h3 id="privacy">Privacy</h3>
21922192

2193-
[=/Service workers=] introduce new persistent storage features including <a>scope to registration map</a> (for [=/service worker registrations=] and their [=/service workers=]), <a>request to response map</a> and <a>name to cache map</a> (for caches), and <a>script resource map</a> (for script resources). In order to protect users from any potential <a biblio data-biblio-type="informative" lt="unsanctioned-tracking">unsanctioned tracking</a> threat, these persistent storages *should* be cleared when users intend to clear them and *should* maintain and interoperate with existing user controls e.g. purging all existing persistent storages.
2193+
[=/Service workers=] introduce new persistent storage features including <a>scope to registration map</a> (for [=/service worker registrations=] and their [=/service workers=]), <a>request to response map</a> and <a>name to cache map</a> (for caches), and [=script resource/imported scripts map=] (for script resources). In order to protect users from any potential <a biblio data-biblio-type="informative" lt="unsanctioned-tracking">unsanctioned tracking</a> threat, these persistent storages *should* be cleared when users intend to clear them and *should* maintain and interoperate with existing user controls e.g. purging all existing persistent storages.
21942194
</section>
21952195
</section>
21962196

@@ -2527,7 +2527,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
25272527

25282528
Else, continue the rest of these steps after the algorithm's asynchronous completion, with |script| being the asynchronous completion value.
25292529

2530-
1. If |newestWorker| is not null, |newestWorker|'s [=service worker/script url=] [=url/equals=] |job|'s [=job/script url=] with the *exclude fragments flag* set, and |script|'s [=source text=] is a byte-for-byte match with |newestWorker|'s [=script resource=]'s [=source text=], if |script| is a [=classic script=], and |script|'s [=module script/module record=]'s \[[ECMAScriptCode]] is a byte-for-byte match with |newestWorker|'s [=script resource=]'s [=module script/module record=]'s \[[ECMAScriptCode]] otherwise, then:
2530+
1. If |newestWorker| is not null, |newestWorker|'s [=service worker/script url=] [=url/equals=] |job|'s [=job/script url=] with the *exclude fragments flag* set, and the result of invoking [=Check If Service Worker Resources Are Identical=] with |newestWorker|'s [=script resource=], |script|, |registration|, and |job| is true, then:
25312531
1. Invoke <a>Resolve Job Promise</a> with |job| and the {{ServiceWorkerRegistration}} object which represents |registration|.
25322532
1. Invoke <a>Finish Job</a> with |job| and abort these steps.
25332533
1. Else:
@@ -3222,6 +3222,37 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
32223222
1. Return |newestWorker|.
32233223
</section>
32243224

3225+
<section algorithm>
3226+
<h3 id="check-if-service-worker-resources-are-identical-algorithm"><dfn>Check If Service Worker Resources Are Identical</dfn></h3>
3227+
3228+
: Input
3229+
:: |sourceScript|, a [=script=]
3230+
:: |targetScript|, a [=script=]
3231+
:: |registration|, a [=/service worker registration=]
3232+
:: |job|, a [=job=]
3233+
: Output
3234+
:: True or false, a boolean
3235+
3236+
1. If |sourceScript| and |targetScript| are not both [=classic scripts=] or not both [=module scripts=], return false.
3237+
1. If |sourceScript| is a [=classic script=], then:
3238+
1. If |sourceScript|'s [=source text=] is not a byte-for-byte match with |targetScript|'s [=source text=], return false.
3239+
1. Let |sourceMap| be |sourceScript|'s [=script resource/imported scripts map=].
3240+
1. [=map/For each=] |url| → |response| of |sourceMap|:
3241+
1. Let |request| be a new [=/request=] whose [=request/url=] is |url|, [=request/client=] is |job|'s [=job/client=], [=request/type=] is "<code>script</code>", [=request/destination=] is "<code>script</code>", [=request/parser metadata=] is "<code>not parser-inserted</code>", [=request/synchronous flag=] is set, and whose [=request/use-URL-credentials flag=] is set.
3242+
1. Set |request|'s [=request/cache mode=] to "<code>no-cache</code>" if any of the following are true:
3243+
* |registration|'s [=service worker registration/use cache=] is false.
3244+
* |job|'s [=force bypass cache flag=] is set.
3245+
* |registration|'s [=last update check time=] is not null and the time difference in seconds calculated by the current time minus |registration|’s [=last update check time=] is greater than 86400.
3246+
1. Let |targetResponse| be the result of [=fetch|fetching=] |request|.
3247+
1. If |targetResponse|'s <a for="response" href="https://github.com/whatwg/fetch/issues/376">cache state</a> is not "<code>local</code>", set |registration|’s [=last update check time=] to the current time.
3248+
1. Let |targetResponse| be |targetResponse|'s [=unsafe response=].
3249+
1. If |targetResponse|'s [=response/type=] is "<code>error</code>", or |targetResponse|'s [=response/status=] is not an [=ok status=], return false.
3250+
1. If the result of [=UTF-8 decoding=] |response|'s [=response/body=] is not a byte-for-byte match with the result of [=UTF-8 decoding=] |targetResponse|'s [=response/body=], return false.
3251+
1. If |sourceScript| is a [=module script=], then:
3252+
1. If |sourceScript|’s [=module script/module record=]'s \[[ECMAScriptCode]] is not a byte-for-byte match with |targetScript|’s [=module script/module record=]'s \[[ECMAScriptCode]], return false.
3253+
1. Return true.
3254+
</section>
3255+
32253256
<section algorithm>
32263257
<h3 id="create-client-algorithm"><dfn>Create Client</dfn></h3>
32273258

0 commit comments

Comments
 (0)