Skip to content

Commit 9dd5319

Browse files
npm1annevk
authored andcommitted
Add TAO check
This adds a Timing Allow Origin (TAO) check (for the Timing-Allow-Origin header), aligned with most of the security principles of CORS. (The exception is that a wildcard is okay for credentialed requests.) Tests: resource-timing/crossorigin-sandwich-TAO.sub.html. Future refactoring of Resource Timing will move more of the primitives into Fetch.
1 parent 493c021 commit 9dd5319

File tree

1 file changed

+66
-16
lines changed

1 file changed

+66
-16
lines changed

fetch.bs

Lines changed: 66 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1548,10 +1548,15 @@ Unless stated otherwise, it is unset.
15481548
<p>A <a for=/>request</a> has an associated <dfn export for=request id=done-flag>done flag</dfn>.
15491549
Unless stated otherwise, it is unset.
15501550

1551+
<p>A <a for=/>request</a> has an associated
1552+
<dfn export for=request id=timing-allow-failed>timing allow failed flag</dfn>. Unless stated
1553+
otherwise, it is unset.
1554+
15511555
<p class="note no-backref">A <a for=/>request</a>'s <a for=request>tainted origin flag</a>,
15521556
<a for=request>URL list</a>, <a for=request>current URL</a>, <a for=request>redirect count</a>,
1553-
<a for=request>response tainting</a>, and <a for=request>done flag</a> are used as bookkeeping
1554-
details by the <a for=/>fetch</a> algorithm.
1557+
<a for=request>response tainting</a>, <a for=request>done flag</a>, and
1558+
<a for=request>timing allow failed flag</a> are used as bookkeeping details by the
1559+
<a for=/>fetch</a> algorithm.
15551560

15561561
<hr>
15571562

@@ -1585,12 +1590,16 @@ run these steps:
15851590

15861591
<ol>
15871592
<li><p>If <var>request</var>'s <a for=request>tainted origin flag</a> is set, then return
1588-
`<code>null</code>`.
1593+
"<code>null</code>".
15891594

15901595
<li><p>Return <var>request</var>'s <a for=request>origin</a>,
1591-
<a lt="ASCII serialization of an origin">serialized</a> and <a>isomorphic encoded</a>.
1596+
<a lt="ASCII serialization of an origin">serialized</a>.
15921597
</ol>
15931598

1599+
<p><dfn>Byte-serializing a request origin</dfn>, given a <a for=/>request</a> <var>request</var>,
1600+
is to return the result of <a>serializing a request origin</a> with <var>request</var>,
1601+
<a>isomorphic encoded</a>.
1602+
15941603
<hr>
15951604

15961605
<p>To <dfn export for=request id=concept-request-clone>clone</dfn> a
@@ -1800,6 +1809,15 @@ initially unset.
18001809
being provided to an API that didn't make a range request. See the flag's usage for a detailed
18011810
description of the attack.
18021811

1812+
<p>A <a for=/>response</a> has an associated
1813+
<dfn for=response id=concept-response-timing-allow-passed>timing allow passed flag</dfn>, which is
1814+
initially unset.
1815+
1816+
<p class=note>This is used so that the caller to a fetch can determine if sensitive timing data is
1817+
allowed on the resource fetched by looking at the flag of the response returned. Because the flag on
1818+
the response of a redirect has to be set if it was set for previous responses in the redirect chain,
1819+
this is also tracked internally using the request's <a for=request>timing allow failed flag</a>.
1820+
18031821
<p>A <a for=/>response</a> can have an associated
18041822
<dfn export for=response id=concept-response-location-url>location URL</dfn> (null, failure, or a
18051823
<a for=/>URL</a>). Unless specified otherwise, <a for=/>response</a> has no
@@ -2415,8 +2433,8 @@ origin = <a for=url>scheme</a> "://" <a for=url>host</
24152433
given a <a for=/>request</a> <var>request</var>, run these steps:
24162434

24172435
<ol>
2418-
<li><p>Let <var>serializedOrigin</var> be the result of <a>serializing a request origin</a> with
2419-
<var>request</var>.
2436+
<li><p>Let <var>serializedOrigin</var> be the result of <a>byte-serializing a request origin</a>
2437+
with <var>request</var>.
24202438

24212439
<li><p>If <var>request</var>'s <a for=request>response tainting</a> is "<code>cors</code>" or
24222440
<var>request</var>'s <a for=request>mode</a> is "<code>websocket</code>", then
@@ -3526,6 +3544,9 @@ optionally with a <i>recursive flag</i>, run these steps:
35263544
<!-- If you are ever tempted to move this around, carefully consider responses from about URLs,
35273545
blob URLs, service workers, HTTP cache, HTTP network, etc. -->
35283546

3547+
<li><p>If <var>request</var>'s <a for=request>timing allow failed flag</a> is unset, then set
3548+
<var>internalResponse</var>'s <a for=response>timing allow passed flag</a>.
3549+
35293550
<li><p><a href=https://w3c.github.io/webappsec-csp/#set-response-csp-list>Set <var>internalResponse</var>'s CSP list</a>.
35303551
[[!CSP]]
35313552

@@ -3892,6 +3913,9 @@ optional <i>CORS-preflight flag</i>, run these steps:
38923913
<p class="note no-backref">As the <a>CORS check</a> is not to be applied to
38933914
<a for=/>responses</a> whose <a for=response>status</a> is <code>304</code> or <code>407</code>,
38943915
or <a for=/>responses</a> from a service worker for that matter, it is applied here.
3916+
3917+
<li><p>If the <a>TAO check</a> for <var>request</var> and <var>response</var> returns failure,
3918+
then set <var>request</var>'s <a for=request>timing allow failed flag</a>.
38953919
</ol>
38963920

38973921
<li>
@@ -4943,7 +4967,7 @@ run these steps:
49434967
<p>A <dfn>cache entry</dfn> consists of:
49444968

49454969
<ul class=brief>
4946-
<li><dfn id=concept-cache-origin for="cache entry">serialized origin</dfn> (a
4970+
<li><dfn id=concept-cache-origin for="cache entry">byte-serialized origin</dfn> (a
49474971
<a for=/>byte sequence</a>)
49484972
<li><dfn id=concept-cache-url for="cache entry">URL</dfn> (a <a for=/>URL</a>)
49494973
<li><dfn id=concept-cache-max-age for="cache entry">max-age</dfn> (a number of seconds)
@@ -4966,8 +4990,8 @@ be removed before that moment arrives.
49664990
<p>Let <var>entry</var> be a <a>cache entry</a>, initialized as follows:
49674991

49684992
<dl>
4969-
<dt><a for="cache entry">serialized origin</a>
4970-
<dd><p>The result of <a>serializing a request origin</a> with <var>request</var>
4993+
<dt><a for="cache entry">byte-serialized origin</a>
4994+
<dd><p>The result of <a>byte-serializing a request origin</a> with <var>request</var>
49714995

49724996
<dt><a for="cache entry">URL</a>
49734997
<dd><p><var>request</var>'s <a for=request>current URL</a>
@@ -4991,15 +5015,15 @@ be removed before that moment arrives.
49915015

49925016
<p>To <dfn id=concept-cache-clear>clear cache entries</dfn>, given a <var>request</var>,
49935017
<a for=list>remove</a> any <a>cache entries</a> in the user agent's <a>CORS-preflight cache</a>
4994-
whose <a for="cache entry">serialized origin</a> is the result of
4995-
<a>serializing a request origin</a> with <var>request</var> and whose <a for="cache entry">URL</a>
4996-
is <var>request</var>'s <a for=request>current URL</a>.
5018+
whose <a for="cache entry">byte-serialized origin</a> is the result of
5019+
<a>byte-serializing a request origin</a> with <var>request</var> and whose
5020+
<a for="cache entry">URL</a> is <var>request</var>'s <a for=request>current URL</a>.
49975021

49985022
<p>There is a <dfn id=concept-cache-match>cache entry match</dfn> for a <a>cache entry</a>
49995023
<var>entry</var> with <var>request</var> if <var>entry</var>'s
5000-
<a for="cache entry">serialized origin</a> is the result of <a>serializing a request origin</a> with
5001-
<var>request</var>, <var>entry</var>'s <a for="cache entry">URL</a> is <var>request</var>'s
5002-
<a for=request>current URL</a>, and one of
5024+
<a for="cache entry">byte-serialized origin</a> is the result of
5025+
<a>byte-serializing a request origin</a> with <var>request</var>, <var>entry</var>'s
5026+
<a for="cache entry">URL</a> is <var>request</var>'s <a for=request>current URL</a>, and one of
50035027

50045028
<ul class=brief>
50055029
<li><var>entry</var>'s <a for="cache entry">credentials</a> is true
@@ -5047,7 +5071,7 @@ agent's <a>CORS-preflight cache</a> for which there is a <a>cache entry match</a
50475071
<li><p>If <var>request</var>'s <a for=request>credentials mode</a> is not "<code>include</code>"
50485072
and <var>origin</var> is `<code>*</code>`, then return success.
50495073

5050-
<li><p>If the result of <a>serializing a request origin</a> with <var>request</var> is not
5074+
<li><p>If the result of <a>byte-serializing a request origin</a> with <var>request</var> is not
50515075
<var>origin</var>, then return failure.
50525076

50535077
<li><p>If <var>request</var>'s <a for=request>credentials mode</a> is not "<code>include</code>",
@@ -5063,6 +5087,31 @@ agent's <a>CORS-preflight cache</a> for which there is a <a>cache entry match</a
50635087
</ol>
50645088

50655089

5090+
<h3 id=tao-check>TAO check</h3>
5091+
5092+
<p>To perform a <dfn id=concept-tao-check>TAO check</dfn> for a <var>request</var> and
5093+
<var>response</var>, run these steps:
5094+
5095+
<ol>
5096+
<li><p>If <var>request</var>'s <a for=request>timing allow failed flag</a> is set, then return
5097+
failure.
5098+
5099+
<li><p>If <var>request</var>'s <a for=request>response tainting</a> is "<code>basic</code>", then
5100+
return success.
5101+
5102+
<li><p>Let <var>values</var> be the result of
5103+
<a for="header list">getting, decoding, and splitting</a> `<code>Timing-Allow-Origin</code>` from
5104+
<var>response</var>'s <a for=response>header list</a>.
5105+
5106+
<li><p>If <var>values</var> <a for=list>contains</a> "<code>*</code>", then return success.
5107+
5108+
<li><p>If <var>values</var> <a for=list>contains</a> the result of
5109+
<a>serializing a request origin</a> with <var>request</var>, then return success.
5110+
5111+
<li><p>Return failure.
5112+
</ol>
5113+
5114+
50665115

50675116
<h2 id=fetch-api>Fetch API</h2>
50685117

@@ -7196,6 +7245,7 @@ Mohammed Zubair Ahmed<!-- M-ZubairAhmed; GitHub -->,
71967245
Moritz Kneilmann,
71977246
Ms2ger,
71987247
Nico Schlömer,
7248+
Nicolás Peña Moreno,
71997249
Nikhil Marathe,
72007250
Nikki Bee,
72017251
Nikunj Mehta,

0 commit comments

Comments
 (0)