Skip to content

Commit 3f24fad

Browse files
authored
Make all prerenders go via prefetching first (#359)
This allows deduplicating a good amount of the No-Vary-Search handling that both needed to do, and eliminates the entire "prerender records" concept. Fixes #320 by properly specifying Sec-Purpose for prerenders.
1 parent 24b2405 commit 3f24fad

File tree

3 files changed

+64
-75
lines changed

3 files changed

+64
-75
lines changed

prefetch.bs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ A <dfn export>prefetch record</dfn> is a [=struct=] with the following [=struct/
182182
* <dfn export for="prefetch record">label</dfn>, a [=string=]
183183

184184
<div class="note">This is intended for use by a specification or [=implementation-defined=] feature to identify which prefetches it created. It might also associate other data with this struct.</div>
185+
* <dfn export for="prefetch record">prerendering traversable</dfn>, a [=prerendering traversable=], "`to be created`", or null (null by default)
185186
* <dfn export for="prefetch record">state</dfn>, which is "`ongoing`" (the default), "`completed`", or "`canceled`"
186187
<div class="note">"`canceled`" indicates that the prefetch was aborted by the author or user, or terminated by the user agent.</div>
187188
* <dfn export for="prefetch record">fetch controller</dfn>, a [=fetch controller=] (a new [=fetch controller=] by default)
@@ -533,10 +534,11 @@ Modify the [=snapshot source snapshot params=] algorithm to set the return value
533534
1. If |prefetchRecord| was given, then:
534535
1. Let |purpose| be a [=structured header/List=] containing the [=structured header/Token=] `prefetch`.
535536
1. If |prefetchRecord|'s [=prefetch record/anonymization policy=] [=prefetch IP anonymization policy/requires anonymity=] for |request|, then:
536-
1. Add a parameter whose key is <a for="Sec-Purpose prefetch" lt="anonymous-client-ip">"`anonymous-client-ip`"</a> and whose value is true to the `prefetch` token in |purpose|.
537+
1. Add a parameter whose key is "<a for="Sec-Purpose prefetch">`anonymous-client-ip`</a>" and whose value is true to the `prefetch` token in |purpose|.
537538
1. The user agent must use a [=connection=] which anonymizes the client IP address (e.g., using a proxy) when fetching |request|, or set |response| to a [=network error=] and [=iteration/break=].
538539

539540
<p class="issue">At the moment, how IP anonymization is achieved is handwaved. This will probably be done in an [=implementation-defined=] manner using some kind of proxy or relay. Ideally this would be plumbed down to [=obtain a connection=], and possibly even the mechanism could be further standardized.</p>
541+
1. If |prefetchRecord|'s [=prefetch record/prerendering traversable=] is not null, then add a parameter whose key is "<a for="Sec-Purpose prefetch">`prerender`</a>" and whose value is true to the `prefetch` token in |purpose|.
540542
1. [=header list/Set a structured field value=] given (<a http-header>`` `Sec-Purpose` ``</a>, |purpose|) in |request|'s [=request/header list=].
541543

542544
<div class="note">
@@ -662,13 +664,13 @@ This section contains patches to [[NAVIGATION-TIMING]].
662664
The <dfn>list of sufficiently strict speculative navigation referrer policies</dfn> is a list containing the following: "", "`strict-origin-when-cross-origin`", "`strict-origin`", "`same-origin`", "`no-referrer`".
663665

664666
<div algorithm>
665-
To <dfn export>prefetch</dfn> given a {{Document}} document and a [=prefetch record=] |prefetchRecord|, perform the following steps.
667+
To <dfn export>prefetch</dfn> given a {{Document}} |document| and a [=prefetch record=] |prefetchRecord|, perform the following steps.
666668

667669
1. Let |sourceSnapshotParams| be the result of [=snapshotting source snapshot params=] given |document|.
668670
1. Let |targetSnapshotParams| be the result of [=snapshotting target snapshot params=] given |document|'s [=node navigable=].
669671
1. Set |prefetchRecord|'s [=prefetch record/source partition key=] to the result of [=determining the network partition key=] given |document|'s [=relevant settings object=].
670672
1. [=Assert=]: |prefetchRecord|'s [=prefetch record/URL=]'s [=url/scheme=] is an [=HTTP(S) scheme=].
671-
1. [=list/Append=] |prefetchRecord| to |document|'s [=Document/prefetch records=]
673+
1. [=list/Append=] |prefetchRecord| to |document|'s [=Document/prefetch records=].
672674
1. Set |prefetchRecord|'s [=prefetch record/start time=] to the [=current high resolution time=] for the [=relevant global object=] of |document|.
673675
1. Set |prefetchRecord|'s [=prefetch record/sandboxing flag set=] to the result of [=determining the creation sandboxing flags=] for |document|'s [=Document/browsing context=] given |document|'s [=node navigable=]'s [=navigable/container=].
674676
1. Let |referrerPolicy| be |prefetchRecord|'s [=prefetch record/referrer policy=] if |prefetchRecord|'s [=prefetch record/referrer policy=] is not the empty string, and |document|'s [=Document/policy container=]'s [=policy container/referrer policy=] otherwise.
@@ -768,19 +770,13 @@ The <dfn>list of sufficiently strict speculative navigation referrer policies</d
768770

769771
The <dfn http-header>`` `Sec-Purpose` ``</dfn> HTTP request header specifies that the request serves one or more purposes other than requesting the resource for immediate use by the user.
770772

771-
The header field is an [[RFC9651]] Structured Header whose value must be a [=structured header/List=]. Its ABNF is:
773+
The header field is an [[RFC9651]] Structured Header whose value must be a [=structured header/List=].
772774

773-
```
774-
Sec-Purpose = sf-list
775-
```
775+
It may contain an [=structured header/Item=] member which is the [=structured header/Token=] `prefetch`. If so, this indicates the request's purpose is to download a resource it is anticipated will be fetched shortly.
776776

777-
It may contain an [=structured header/Item=] member which is the [=structured header/Token=] "`prefetch`". If so, this indicates the request's purpose is to download a resource it is anticipated will be fetched shortly.
777+
The following parameters are defined for the `prefetch` token:
778778

779-
<div class="issue">TODO: Are there normative implications of this that should be specified here?</div>
780-
781-
The following parameters are defined for the "`prefetch`" token:
782-
783-
* A parameter whose key is <dfn for="Sec-Purpose prefetch" lt="anonymous-client-ip">"`anonymous-client-ip`"</dfn>.
779+
* A parameter whose key is "<dfn for="Sec-Purpose prefetch">`anonymous-client-ip`</dfn>".
784780

785781
If present with a value other than boolean false (`` `?0` `` in the field value), this parameter indicates that the prefetch request is being made using an anonymous client IP. Consequently, servers should not rely on it matching, or sharing a geographic location or network operator with, the client's IP address from which a non-prefetch request would have been made.
786782

@@ -792,6 +788,17 @@ The following parameters are defined for the "`prefetch`" token:
792788
This specification conforms to this advice; the [=prefetch=] algorithm does not emit non-boolean values.
793789
</div>
794790

791+
* A parameter whose key is "<dfn for="Sec-Purpose prefetch">`prerender`</dfn>".
792+
793+
If present with a value other than boolean false (`` `?0` `` in the field value), this parameter indicates that the prefetch request is being made in anticipation of a prerender.
794+
795+
<div class="note">
796+
A future specification might define assign more specific meaning to non-boolean values. For now, they are treated the same as true. Implementations are advised not to emit such values.
797+
798+
This specification conforms to this advice; the [=prefetch=] algorithm does not emit non-boolean values.
799+
</div>
800+
801+
795802
<h2 id="security-considerations">Security considerations</h2>
796803

797804
See <a href="speculation-rules.html#security-considerations">Security considerations (Speculation Rules)</a>.

0 commit comments

Comments
 (0)