Skip to content

Commit 53fb61a

Browse files
carlosjoan91annevk
authored andcommitted
Add HTTPS Upgrading
HTTPS Upgrading automatically and optimistically upgrades all HTTP navigations to HTTPS, with a fallback to HTTP. If an upgraded navigation fails, the user agent will fallback to the original HTTP navigation. Tests: web-platform-tests/wpt/tree/HEAD/https-upgrades
1 parent 8dd73db commit 53fb61a

File tree

1 file changed

+137
-2
lines changed

1 file changed

+137
-2
lines changed

fetch.bs

Lines changed: 137 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2162,6 +2162,17 @@ Unless stated otherwise, it is false.
21622162

21632163
<p class=note>This flag is for exclusive use by HTML's render-blocking mechanism. [[!HTML]]
21642164

2165+
<p>A <a for=/>request</a> has an associated boolean <dfn export for=request>is HTTPS upgrade</dfn>.
2166+
Unless stated otherwise, it is false.
2167+
2168+
<p class=note>This is for exclusive use by HTTPS upgrading.
2169+
2170+
<p>A <a for=/>request</a> has an associated
2171+
<dfn export for=request>HTTPS upgrade fallback URL</dfn>, which is null or a <a for=/>URL</a>.
2172+
Unless otherwise stated, it is null.
2173+
2174+
<p class=note>This is for exclusive use by HTTPS upgrading.
2175+
21652176
<hr>
21662177

21672178
<p>A <a for=/>request</a> has an associated
@@ -3270,6 +3281,120 @@ through TLS using ALPN. The protocol cannot be spoofed through HTTP requests in
32703281
</div>
32713282

32723283

3284+
<h3 id=https-upgrading>HTTPS upgrading</h3>
3285+
3286+
<p>User agents may optionally upgrade requests with URLs that are not
3287+
<a>potentially trustworthy URLs</a> to attempt to fetch them over
3288+
<a>potentially trustworthy URLs</a>. If an upgraded request fails with a network error, it is
3289+
retried over the original URL.
3290+
3291+
<p>The HTTPS upgrading algorithm consists of <a>upgrade an HTTP request</a> and
3292+
<a>HTTPS upgrade fallback</a> algorithms.
3293+
3294+
3295+
<h4 id=https-upgrading-upgrade>HTTPS upgrade algorithm</h4>
3296+
3297+
<div algorithm>
3298+
<p>To <dfn>upgrade an HTTP request</dfn> given a <a for=/>request</a> <var>request</var>:
3299+
3300+
<ol>
3301+
<li>
3302+
<p>If one or more of the following conditions are met, return:
3303+
<ul>
3304+
<li><p><var>request</var>'s <a for="request">destination</a> is not "<code>document</code>"
3305+
3306+
<li><p><var>request</var>'s <a for="request">method</a> is not "<code>GET</code>"
3307+
3308+
<li><p><var>request</var>'s <a for="request">URL</a>'s <a for="url">scheme</a> is not
3309+
"<code>http</code>"
3310+
3311+
<li><p><var>request</var>'s <a for="request">URL</a>'s <a for="url">origin</a> is exempted from
3312+
upgrades in an <a>implementation-defined</a> way.
3313+
</ul>
3314+
</li>
3315+
3316+
<li>
3317+
<p>If <var>request</var>'s <a for=request>HTTPS upgrade fallback URL</a> is non-null, set
3318+
<a for=request>is HTTPS upgrade</a> to false and <a for=request>HTTPS upgrade fallback URL</a> to
3319+
null and return.
3320+
3321+
<p class=note>This is a fallback request that cannot be upgraded again.
3322+
3323+
<li>
3324+
<p>Otherwise:
3325+
<ul>
3326+
<li><p>Set <a for=request>HTTPS upgrade fallback URL</a> to <var>request</var>'s
3327+
<a for="request">URL</a>.
3328+
3329+
<li><p>Set <var>request</var>'s <a for="request">URL</a>'s <a for="url">scheme</a> to
3330+
"<code>https</code>".
3331+
3332+
<li><p>Set <a for=request>is HTTPS upgrade</a> to true.
3333+
</ul>
3334+
</li>
3335+
</ol>
3336+
</div>
3337+
3338+
3339+
<h4 id=https-upgrading-fallback>Fallback algorithm</h4>
3340+
3341+
<div algorithm>
3342+
<p>To run <dfn>HTTPS upgrade fallback</dfn> given a <a for=/>request</a> <var>request</var> and
3343+
<a for=/>response</a> <var>response</var>:
3344+
3345+
<ol>
3346+
<li><p>If <var>request</var>'s <a for=request>is HTTPS upgrade</a> is false, then return
3347+
<var>response</var>.
3348+
3349+
<li>
3350+
<p>If <var>response</var> is a <a>network error</a>:
3351+
3352+
<p class=note>This means that the upgrade failed and initiates a fallback load.
3353+
3354+
<ol>
3355+
<li><p>Let <var>serializedFallbackUrl</var> be the <var>request</var>'s
3356+
<a for=request>HTTPS upgrade fallback URL</a>, <a lt="URL serializer">serialized</a> and
3357+
<a>isomorphic encoded</a>.
3358+
3359+
<li><p>Let <var>fallbackResponse</var> be a new <a for=/>response</a> whose
3360+
<a for=response>header list</a> is «
3361+
(`<code>Location</code>`, <var>serializedFallbackUrl</var>) » and
3362+
<a for="response">status</a> is 307.
3363+
3364+
<li><p>Return <var>fallbackResponse</var>.
3365+
</ol>
3366+
3367+
<li>
3368+
<p>Return <var>response</var>.
3369+
3370+
<p class=note>This means the upgrade was successful.
3371+
</ol>
3372+
3373+
<p class=note>User agents can implement a fast-fallback path by canceling slow fetches on upgraded
3374+
requests, in order to quickly initiate a fallback HTTP fetch.
3375+
</div>
3376+
3377+
3378+
<h4 id=http-upgrades-examples>Examples</h4>
3379+
3380+
<p id=example-https-upgrade-good-https class=example><code>a.com</code> serves both
3381+
<code>http://a.com</code> and <code>https://a.com</code>. An eligible request to
3382+
<code>http://a.com</code> will be upgraded to <code>https://a.com</code>.
3383+
3384+
<p id=example-https-upgrade-bad-https class=example><code>a.com</code> serves
3385+
<code>http://a.com</code> but refuses connections on <code>https://a.com</code>. An eligible
3386+
request to <code>http://a.com</code> will be upgraded to <code>https://a.com</code>, but the fetch
3387+
will fail. A fallback request will be initiated to <code>http://a.com</code>.
3388+
3389+
<p id=example-https-upgrade-allowlist class=example><code>site.test</code> serves
3390+
<code>http://site.test</code> but refuses connections on <code>https://site.test</code>. Upon
3391+
first request and fallback to <code>http://site.test</code>, the user agent stores the hostname
3392+
in an allowlist with an expiration time of 7 days. In a future request, if <code>site.test</code>
3393+
is still in this allowlist, the user agent will not upgrade <code>http://site.test</code> to
3394+
<code>https://site.test</code>. The user agent will also set the new expiration time of the
3395+
allowlist entry for <code>site.test</code> to 7 days from now.
3396+
3397+
32733398

32743399
<h2 id=http-extensions>HTTP extensions</h2>
32753400

@@ -4457,6 +4582,14 @@ steps:
44574582

44584583
<li><p><a>Upgrade <var>request</var> to a potentially trustworthy URL, if appropriate</a>.
44594584

4585+
<li>
4586+
<p>Optionally, run <a>upgrade an HTTP request</a> algorithm on <var>request</var>.
4587+
4588+
<p class=note>HTTPS upgrading only applies to requests with <a>HTTP(S) scheme</a>s, but it's done
4589+
in <a>main fetch</a> instead of <a>HTTP fetch</a> to ensure that
4590+
<a>upgrade a mixed content <var>request</var> to a potentially trustworthy URL, if appropriate</a>
4591+
step runs next and applies to the upgraded request.
4592+
44604593
<li><p><a>Upgrade a mixed content <var>request</var> to a potentially trustworthy URL, if appropriate</a>.
44614594

44624595
<li><p>If <a lt="block bad port">should <var>request</var> be blocked due to a bad port</a>,
@@ -6001,7 +6134,8 @@ optional boolean <var>forceNewConnection</var> (default false), run these steps:
60016134
<a for="fetch params">canceled</a>:
60026135

60036136
<ol>
6004-
<li><p>If <var>connection</var> is failure, then return a <a>network error</a>.
6137+
<li><p>If <var>connection</var> is failure, then return the result of running
6138+
<a>HTTPS upgrade fallback</a> given <var>request</var> and <a>network error</a>.
60056139

60066140
<li><p>Set <var>timingInfo</var>'s <a for="fetch timing info">final connection timing info</a> to
60076141
the result of calling <a>clamp and coarsen connection timing info</a> with
@@ -8727,7 +8861,7 @@ resource — for non-<a>CORS requests</a> as well as <a>CORS
87278861
requests</a> — and do not use `<code>Vary</code>`.
87288862

87298863

8730-
<h3 class=no-num id=websocket-protocol oldids=websocket-connections,websocket-opening-handshake,fail-the-websocket-connection,the-websocket-connection-is-established>WebSockets</h2>
8864+
<h3 class=no-num id=websocket-protocol oldids=websocket-connections,websocket-opening-handshake,fail-the-websocket-connection,the-websocket-connection-is-established>WebSockets</h3>
87318865

87328866
<p>As part of establishing a connection, the {{WebSocket}} object initiates a special kind of
87338867
<a for=/>fetch</a> (using a <a for=/>request</a> whose <a for=request>mode</a> is
@@ -8991,6 +9125,7 @@ done only by navigations). The <a>fetch controller</a> is also used to
89919125
<a for=request>redirect mode</a> set to "<code>manual</code>".
89929126

89939127

9128+
89949129
<h2 id=acknowledgments class=no-num>Acknowledgments</h2>
89959130

89969131
<p>Thanks to

0 commit comments

Comments
 (0)