Skip to content

Commit e326dd8

Browse files
committed
Prohibit child navigable prefetches and clarify more navigable issues
Closes #384
1 parent b226d1f commit e326dd8

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

prefetch.bs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ Modify the [=snapshot source snapshot params=] algorithm to set the return value
556556
1. Let |request| be the result of [=creating a navigation request=] given <var ignore>entry</var>, <var ignore>sourceSnapshotParams</var>'s [=source snapshot params/fetch client=], <var ignore>navigable</var>'s [=navigable/container=], and <var ignore>sourceSnapshotParams</var>'s [=source snapshot params/has transient activation=].
557557
1. Set |request|'s [=request/replaces client id=] to <var ignore>navigable</var>'s [=navigable/active document=]'s [=relevant settings object=]'s [=environment/id=].
558558
1. Let |prefetched| be false.
559-
1. If <var ignore>documentResource</var> is null:
559+
1. If <var ignore>documentResource</var> is null and <var ignore>navigable</var> is a [=top-level traversable=]:
560560
1. Let |prefetchRecord| be the result of [=waiting for a matching prefetch record=] given <var ignore>navigable</var>, <var ignore>sourceSnapshotParams</var>, <var ignore>entry</var>'s [=session history entry/URL=], and <var ignore>sourceSnapshotParams</var>'s [=source snapshot params/sandboxing flags=].
561561
1. If |prefetchRecord| is not null:
562562
1. Set <var ignore>navigationParams</var> to the result of [=creating navigation params from a prefetch record=] given <var ignore>navigable</var>, <var ignore>entry</var>'s [=session history entry/document state=], <var ignore>navigationId</var>, <var ignore>navTimingType</var>, <var ignore>request</var>, |prefetchRecord|, <var ignore>targetSnapshotParams</var>, and <var ignore>sourceSnapshotParams</var>.
@@ -565,7 +565,7 @@ Modify the [=snapshot source snapshot params=] algorithm to set the return value
565565
<div class="note">This copy is complete before continuing, in the sense that subresource fetches, {{Document/cookie|document.cookie}}, etc. can observe the cookies. If the prefetch never reached a cross-site URL, there will be no cookies to copy.</div>
566566
1. Set |prefetched| to true.
567567

568-
<p class="note">This means that prefetches are only ever used to fulfill \``GET`\` requests.</p>
568+
<p class="note">This means that prefetches are only ever used to fulfill \``GET`\` requests, and only ever activated into [=top-level traversables=].</p>
569569
1. If |prefetched| is false:
570570
1. Let |coopEnforcementResult| be the result of [=creating a cross-origin opener policy enforcement result for navigation=] given <var ignore>navigable</var>'s [=navigable/active document=] and <var ignore>entry</var>'s [=session history entry/document state=]'s [=document state/initiator origin=].
571571
1. Set <var ignore>navigationParams</var> to the result of [=creating navigation params by fetching=] given |request|, <var ignore>entry</var>, |coopEnforcementResult|, <var ignore>navigable</var>, <var ignore>sourceSnapshotParams</var>, <var ignore>targetSnapshotParams</var>, <var ignore>cspNavigationType</var>, <var ignore>navigationId</var>, and <var ignore>navTimingType</var>.
@@ -794,6 +794,9 @@ The <dfn>list of sufficiently strict speculative navigation referrer policies</d
794794
<div algorithm>
795795
To <dfn export>prefetch</dfn> given a {{Document}} |document| and a [=prefetch record=] |prefetchRecord|, perform the following steps.
796796

797+
1. [=Assert=]: |document|'s [=node navigable=] is a [=top-level traversable=].
798+
799+
<p class="note" id="note-prefetch-top-level">Supporting prefetches in [=child navigables=] has some complexities and is not currently defined. It might be possible to define in the future.</p>
797800
1. If |document| [=has a matching prefetch record=] given |prefetchRecord|, then return.
798801
1. Let |sourceSnapshotParams| be the result of [=snapshotting source snapshot params=] given |document|.
799802
1. Let |targetSnapshotParams| be the result of [=snapshotting target snapshot params=] given |document|'s [=node navigable=].
@@ -818,6 +821,18 @@ The <dfn>list of sufficiently strict speculative navigation referrer policies</d
818821
1. Let |global| be |document|'s [=relevant global object=].
819822
1. [=In parallel=]:
820823
1. Let |navigationParams| be the result of [=creating navigation params by fetching=] given |request|, |entry|, |coopEnforcementResult|, |document|'s [=node navigable=], |sourceSnapshotParams|, |targetSnapshotParams|, "`other`", null (navigationId), "`navigate`", and <a href="#create-navigation-params-by-fetching-prefetchRecord"><i>prefetchRecord</i></a> |prefetchRecord|.
824+
825+
<div class="note" id="note-create-navingation-params-navigable">
826+
The [=navigable=] used here, i.e. |document|'s [=node navigable=], could potentially be different from the one that might be used when calling [=create navigation params by fetching=] for a non-prefetched navigation. The latter case would use the target navigable passed the [=navigate=] algorithm, whereas prefetch records are looked up on the initiator document of the navigation.
827+
828+
This is, actually, fine. During the [=navigate|navigation=] that results in prefetch activation, the target navigable will still be used for most of the important checks, which are performed earlier in the process before <a spec=HTML>attempt to populate the history entry's document</a> is called, and thus before [=create navigation params by fetching=] would be called. Of the checks that are perform during [=create navigation params by fetching=]:
829+
830+
* Some, such as those for [:Cross-Origin-Resource-Policy:], are not applicable, since <a href="#note-prefetch-top-level">prefetches are only supported in top-level navigables</a>.
831+
* Checks related to [:Cross-Origin-Opener-Policy:] are re-performed during activation.
832+
833+
Also note that within this algorithm, |navigationParams| is not stored, so the value of |navigationParams|'s [=navigation params/navigable=] does not leak to the rest of the system. In particular, during activation a new [=navigation params=] is created by the [=create navigation params from a prefetch record=] algorithm, which contains the correct target navigable.
834+
</div>
835+
821836
1. If |navigationParams|'s [=navigation params/response=] does not [=support prefetch=], then set |navigationParams| to null.
822837
1. If |prefetchRecord|'s [=prefetch record/had conflicting credentials=] is true, then set |navigationParams| to null.
823838

speculation-rules.bs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ spec: nav-speculation; urlPrefix: prefetch.html
8686
spec: nav-speculation; urlPrefix: prerendering.html
8787
type: dfn
8888
text: start referrer-initiated prerendering; url: start-referrer-initiated-prerendering
89+
text: prerendering navigable; url: prerendering-navigable
8990
text: prerendering traversable; url: prerendering-traversable
9091
text: activate; for: prerendering traversable; url: prerendering-traversable-activate
9192
spec: no-vary-search; urlPrefix: https://httpwg.org/http-extensions/draft-ietf-httpbis-no-vary-search.html
@@ -614,6 +615,14 @@ A <dfn>prerender candidate</dfn> is a [=speculative load candidate=] with the fo
614615
<div algorithm="consider speculation">
615616
To <dfn>consider speculation</dfn> for a [=document=] |document|:
616617

618+
1. If |document|'s [=node navigable=] is not a [=top-level traversable=], then return.
619+
620+
<p class="note" id="note-speculation-top-level">Supporting speculative loads in [=child navigables=] has some complexities and is not currently defined. It might be possible to define in the future.</p>
621+
622+
1. If |document|'s [=node navigable=] is a [=prerendering navigable=], then return.
623+
624+
<p class="note" id="note-speculation-prerendering">Speculative loads in prerendering navigables would be too potentially wasteful.</p>
625+
617626
1. [=Queue a microtask=] that runs the following steps given |document|:
618627
1. If |document| is not [=Document/fully active=], then return.
619628
<p class="issue">It's likely that we should also handle prerendered documents.

0 commit comments

Comments
 (0)