Skip to content

Commit 4124730

Browse files
mfalkenmustaqahmed
authored andcommitted
Create a new reserved environment for cross-origin redirects
Previously, a navigation would create a reserved environment once and use it for all redirects. This commit changes that so a new environment is created on a cross-origin redirect. We now also run CSP for each redirect. See also w3c/ServiceWorker#1316.
1 parent f1f6f3c commit 4124730

File tree

1 file changed

+73
-36
lines changed

1 file changed

+73
-36
lines changed

source

Lines changed: 73 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2835,6 +2835,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
28352835
<li><dfn data-x="concept-request-header-list" data-x-href="https://fetch.spec.whatwg.org/#concept-request-header-list">header list</dfn></li>
28362836
<li><dfn data-x="concept-request-body" data-x-href="https://fetch.spec.whatwg.org/#concept-request-body">body</dfn></li>
28372837
<li><dfn data-x="concept-request-client" data-x-href="https://fetch.spec.whatwg.org/#concept-request-client">client</dfn></li>
2838+
<li><dfn data-x="concept-request-current-url" data-x-href="https://fetch.spec.whatwg.org/#concept-request-current-url">current URL</dfn></li>
28382839
<li><dfn data-x="concept-request-reserved-client" data-x-href="https://fetch.spec.whatwg.org/#concept-request-reserved-client">reserved client</dfn></li>
28392840
<li><dfn data-x="concept-request-replaces-client-id" data-x-href="https://fetch.spec.whatwg.org/#concept-request-replaces-client-id">replaces client id</dfn></li>
28402841
<li><dfn data-x="concept-request-initiator" data-x-href="https://fetch.spec.whatwg.org/#concept-request-initiator">initiator</dfn></li>
@@ -82150,54 +82151,90 @@ interface <dfn>Location</dfn> { // but see also <a href="#the-location-interface
8215082151
data-x="concept-request-origin">origin</span> to that <span>browsing context scope
8215182152
origin</span>.</p></li>
8215282153

82154+
<li><p>Let <var>done</var> be false and <var>reservedEnvironment</var> be null.</p></li>
82155+
8215382156
<li>
82154-
<p>Create a new <span>environment</span> <var>reservedEnvironment</var>, and set its <span
82155-
data-x="concept-environment-id">id</span> to a new unique opaque string, its <span
82156-
data-x="concept-environment-creation-url">creation URL</span> to <var>request</var>'s
82157-
<span>url</span>, and its <span data-x="concept-environment-target-browsing-context">target
82158-
browsing context</span> to <var>browsingContext</var>.</p>
82157+
<p>While <var>done</var> is false:</p>
8215982158

82160-
<p class="note">The created environment's <span
82161-
data-x="concept-environment-active-service-worker">active service worker</span> is set in the
82162-
<span data-x="on-fetch-request-algorithm">handle fetch</span> algorithm during the fetch if its
82163-
<span data-x="concept-environment-creation-url">creation URL</span> matches a service worker
82164-
registration. <ref spec="SW"></p>
82165-
</li>
82159+
<ol>
82160+
<li><p>Let <var>currentURL</var> be <var>response</var>'s <span
82161+
data-x="concept-response-location-url">location URL</span>, if <var>response</var> is not null,
82162+
and <var>request</var>'s <span data-x="concept-request-current-url">current URL</span>
82163+
otherwise.</p></li>
8216682164

82167-
<li><p>Set <var>request</var>'s <span data-x="concept-request-reserved-client">reserved
82168-
client</span> to <var>reservedEnvironment</var>.</p></li>
82165+
<li>
82166+
<p>If <var>reservedEnvironment</var> is not null and <var>currentURL</var>'s
82167+
<span data-x="concept-url-origin">origin</span> is not the <span
82168+
data-x="same origin">same</span> as <var>reservedEnvironment</var>'s <span
82169+
data-x="concept-environment-creation-url">creation URL</span>'s <span
82170+
data-x="concept-url-origin">origin</span>, then:</p>
8216982171

82170-
<li>
82171-
<p>If the <span>Should navigation request of type from source in target be blocked by Content
82172-
Security Policy?</span> algorithm returns "<code data-x="">Blocked</code>" when executed upon
82173-
<var>request</var>, <var>navigationType</var>, <var>sourceBrowsingContext</var>, and
82174-
<var>browsingContext</var>, then set <var>response</var> to a network error.
82175-
<ref spec="CSP"></p>
82172+
<ol>
82173+
<li><p>Run the <span>environment discarding steps</span> for
82174+
<var>reservedEnvironment</var>.</p></li>
8217682175

82177-
<p>Otherwise:</p>
82176+
<li><p>Set <var>reservedEnvironment</var> to null.</p></li>
82177+
</ol>
82178+
</li>
8217882179

82179-
<ol>
82180-
<!--FETCH--><li><p><span data-x="concept-fetch">Fetch</span> <var>request</var>.</p></li>
82180+
<li><p>If <var>reservedEnvironment</var> is null, then set <var>reservedEnvironment</var> to a
82181+
new <span>environment</span> whose <span data-x="concept-environment-id">id</span> is a
82182+
unique opaque string and <span
82183+
data-x="concept-environment-target-browsing-context">target browsing context</span> is
82184+
<var>browsingContext</var>.</p></li>
8218182185

82182-
<li><p>Wait for the <span data-x="concept-task">task</span> on the <span>networking task
82183-
source</span> to <span>process response</span> and set <var>response</var> to the
82184-
result.</p></li>
82185-
</ol>
82186-
</li>
82186+
<li>
82187+
<p>Set <var>reservedEnvironment</var>'s <span
82188+
data-x="concept-environment-creation-url">creation URL</span> to <var>currentURL</var>.</p>
8218782189

82190+
<p class="note">The created environment's <span
82191+
data-x="concept-environment-active-service-worker">active service worker</span> is set in the
82192+
<span data-x="on-fetch-request-algorithm">Handle Fetch</span> algorithm during the fetch if
82193+
the request URL matches a service worker registration. <ref spec="SW"></p>
82194+
</li>
8218882195

82189-
<li id="navigate-redirect-step">
82190-
<p>If <var>response</var> has a <span data-x="concept-response-location-url">location URL</span>
82191-
and it is either failure or a <span>URL</span> whose <span
82192-
data-x="concept-url-scheme">scheme</span> is an <span>HTTP(S) scheme</span>, then set
82193-
<var>response</var> to the result of performing <span>HTTP-redirect fetch</span> using
82194-
<var>request</var> and <var>response</var> and then run this step again.</p>
82196+
<li><p>Set <var>request</var>'s <span data-x="concept-request-reserved-client">reserved
82197+
client</span> to <var>reservedEnvironment</var>.</p></li>
8219582198

82196-
<p class="note">Navigation handles redirects manually as navigation is the only place in the web
82197-
platform that cares for redirects to <code data-x="mailto protocol">mailto:</code> URLs and
82198-
such.</p>
82199+
<li><p>If the <span>Should navigation request of type from source in target be blocked by
82200+
Content Security Policy?</span> algorithm returns "<code data-x="">Blocked</code>" when
82201+
executed upon <var>request</var>, <var>navigationType</var>, <var>sourceBrowsingContext</var>,
82202+
and <var>browsingContext</var>, then set <var>response</var> to a <span>network error</span>
82203+
and set <var>done</var> to true. <ref spec="CSP"></p></li>
82204+
82205+
<li>
82206+
<p>Otherwise:</p>
82207+
82208+
<ol>
82209+
<li><p>If <var>response</var> is null, <!--FETCH--><span
82210+
data-x="concept-fetch">fetch</span> <var>request</var>.</p></li>
82211+
82212+
<li><p>Otherwise, perform <span>HTTP-redirect fetch</span> using
82213+
<var>request</var> and <var>response</var>.</p></li>
82214+
82215+
<li><p>Wait for the <span data-x="concept-task">task</span> on the <span>networking task
82216+
source</span> to <span>process response</span> and set <var>response</var> to the
82217+
result.</p></li>
82218+
82219+
<li>
82220+
<p>If <var>response</var> does not have a <span
82221+
data-x="concept-response-location-url">location URL</span> or the <span
82222+
data-x="concept-response-location-url">location URL</span> is not a <span>URL</span> whose
82223+
<span data-x="concept-url-scheme">scheme</span> is an <span>HTTP(S) scheme</span>,
82224+
then set <var>done</var> to true.</p>
82225+
82226+
<p class="note">Navigation handles redirects manually as navigation is the only place in
82227+
the web platform that cares for redirects to <code data-x="mailto protocol">mailto:</code>
82228+
URLs and such.</p>
82229+
</li>
82230+
</ol>
82231+
</li>
82232+
</ol>
8219982233
</li>
8220082234

82235+
<li><p>If <var>response</var>'s <span data-x="concept-response-location-url">location URL</span>
82236+
is failure, then set <var>response</var> to a <span>network error</span>.</p></li>
82237+
8220182238
<li><p>Otherwise, if <var>response</var> has a <span
8220282239
data-x="concept-response-location-url">location URL</span> that is a <span>URL</span> whose <span
8220382240
data-x="concept-url-scheme">scheme</span> is "<code data-x="">blob</code>", "<code

0 commit comments

Comments
 (0)