Skip to content

Commit bf8f037

Browse files
authored
Refinements and description of Service-Worker-Allowed. (#1409)
* Require Service-Worker-Allowed to be same-origin to the script URL (#1307) * Add non-normative explanation of Service-Worker-Allowed (#1405) and other mitigations. The text is highly inspired by https://infrequently.org/2014/12/psa-service-workers-are-coming/.
1 parent 86d9414 commit bf8f037

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

docs/index.bs

+24-4
Original file line numberDiff line numberDiff line change
@@ -2123,6 +2123,26 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
21232123
[=/Service workers=] enable this by allowing {{Cache|Caches}} to [=/fetch=] and cache off-origin items. Some restrictions apply, however. First, unlike same-origin resources which are managed in the {{Cache}} as {{Response}} objects whose corresponding [=Response/responses=] are <a>basic filtered response</a>, the objects stored are {{Response}} objects whose corresponding [=Response/responses=] are either <a>CORS filtered responses</a> or <a>opaque filtered responses</a>. They can be passed to {{FetchEvent/respondWith(r)|event.respondWith(r)}} method in the same manner as the {{Response}} objects whose corresponding [=Response/responses=] are <a>basic filtered responses</a>, but cannot be meaningfully created programmatically. These limitations are necessary to preserve the security invariants of the platform. Allowing {{Cache|Caches}} to store them allows applications to avoid re-architecting in most cases.
21242124
</section>
21252125

2126+
<section>
2127+
<h3 id="path-restriction">Path restriction</h3>
2128+
2129+
*This section is non-normative.*
2130+
2131+
In addition to the [[#origin-restriction|origin restriction]], service workers are restricted by the [=url/path=] of the service worker script. For example, a service worker script at <code>https://www.example.com/~bob/sw.js</code> can be registered for the [=scope=] <code>https://www.example.com/~bob/</code> but not for the scope <code>https://www.example.com/</code> or <code>https://www.example.com/~alice/</code>. This provides some protection for sites that host multiple-user content in separated directories on the same origin. However, the path restriction is not considered a hard security boundary, as only origins are. Sites are encouraged to use different origins to securely isolate segments of the site if appropriate.
2132+
2133+
Servers can remove the path restriction by setting a [=Service-Worker-Allowed=] header on the service worker script.
2134+
</section>
2135+
2136+
<section>
2137+
<h3 id="script-request">Service worker script request</h3>
2138+
2139+
*This section is non-normative.*
2140+
2141+
To further defend against malicious registration of a service worker on a site, this specification requires that:
2142+
* The [=Service-Worker=] header is present on service worker script requests, and
2143+
* Service worker scripts are served with a [=JavaScript MIME type=].
2144+
</section>
2145+
21262146
<section>
21272147
<h3 id="implementer-concerns">Implementer Concerns</h3>
21282148

@@ -2474,7 +2494,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
24742494
1. Asynchronously complete these steps with a [=network error=].
24752495
1. Let |serviceWorkerAllowed| be the result of [=extracting header list values=] given \`<code>Service-Worker-Allowed</code>\` and |response|'s [=response/header list=].
24762496

2477-
Note: See the definition of the Service-Worker-Allowed header in Appendix B: Extended HTTP headers.
2497+
Note: See the definition of the [=Service-Worker-Allowed=] header in Appendix B: Extended HTTP headers.
24782498

24792499
1. Set |httpsState| to |response|'s [=response/HTTPS state=].
24802500
1. Set |referrerPolicy| to the result of <a>parse a referrer policy from a <code>Referrer-Policy</code> header</a> of |response|.
@@ -2486,10 +2506,10 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
24862506
1. Set |maxScopeString| to "<code>/</code>" concatenated with the strings, except the last string that denotes the script's file name, in |job|'s [=job/script url=]'s [=url/path=] (including empty strings), separated from each other by "<code>/</code>".
24872507
1. Else:
24882508
1. Let |maxScope| be the result of <a lt="URL parser">parsing</a> |serviceWorkerAllowed| with |job|'s [=job/script url=].
2489-
1. Set |maxScopeString| to "<code>/</code>" concatenated with the strings in |maxScope|'s [=url/path=] (including empty strings), separated from each other by "<code>/</code>".
2509+
1. If |maxScope|'s [=url/origin=] is |job|'s [=job/script url=]'s [=url/origin=], then:
2510+
1. Set |maxScopeString| to "<code>/</code>" concatenated with the strings in |maxScope|'s [=url/path=] (including empty strings), separated from each other by "<code>/</code>".
24902511
1. Let |scopeString| be "<code>/</code>" concatenated with the strings in |scopeURL|'s [=url/path=] (including empty strings), separated from each other by "<code>/</code>".
2491-
1. If |scopeString| starts with |maxScopeString|, do nothing.
2492-
1. Else:
2512+
1. If |maxScopeString| is null or |scopeString| does not start with |maxScopeString|, then:
24932513
1. Invoke [=Reject Job Promise=] with |job| and "{{SecurityError}}" {{DOMException}}.
24942514
1. Asynchronously complete these steps with a <a>network error</a>.
24952515
1. Let |url| be |request|'s [=request/url=].

0 commit comments

Comments
 (0)