Skip to content

Commit 0cec471

Browse files
authored
Define Cross-Origin-Resource-Policy response header
This header makes it easier for sites to block unwanted "no-cors" cross-origin requests. Tests: * web-platform-tests/wpt#11171 * web-platform-tests/wpt#11427 * web-platform-tests/wpt#11428 Follow-up: #760 & #767. Fixes #687.
1 parent 8b070f1 commit 0cec471

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

fetch.bs

+70
Original file line numberDiff line numberDiff line change
@@ -2517,6 +2517,71 @@ run these steps:</p>
25172517
</ol>
25182518

25192519

2520+
<h3 id=cross-origin-resource-policy-header>`<code>Cross-Origin-Resource-Policy</code>` header</h3>
2521+
2522+
<p>The
2523+
`<dfn export http-header id=http-cross-origin-resource-policy><code>Cross-Origin-Resource-Policy</code></dfn>`
2524+
response <a for=/>header</a> can be used to require checking a <a for=/>request</a>'s
2525+
<a for=request>current url</a>'s <a for=url>origin</a> against a <a for=/>request</a>'s
2526+
<a for=request>origin</a> when <a for=/>request</a>'s <a for=request>mode</a> is
2527+
"<code>no-cors</code>".
2528+
2529+
<p>Its <a for=header>value</a> <a>ABNF</a>:
2530+
2531+
<pre>
2532+
Cross-Origin-Resource-Policy = %x73.61.6D.65.2D.6F.72.69.67.69.6E / %x73.61.6D.65.2D.73.69.74.65 ; "same-origin" / "same-site", case-sensitive</pre>
2533+
2534+
<p>To perform a <dfn>cross-origin resource policy check</dfn>, given a <var>request</var> and
2535+
<var>response</var>, run these steps:</p>
2536+
2537+
<ol>
2538+
<li><p>If <var>request</var>'s <a for=request>mode</a> is not "<code>no-cors</code>", then return
2539+
<b>allowed</b>.
2540+
2541+
<li>
2542+
<p>If <var>request</var>'s <a for=request>origin</a> is <a>same origin</a> with
2543+
<var>request</var>'s <a for=request>current url</a>'s <a for=url>origin</a>, then return
2544+
<b>allowed</b>.
2545+
2546+
<p class="note no-backref">While redirects that carry a
2547+
`<a http-header><code>Cross-Origin-Resource-Policy</code></a>` header are checked, redirects
2548+
without such a header resulting in <var>response</var> do not contribute to this algorithm. I.e.,
2549+
<var>request</var>'s <a for=request>tainted origin flag</a> is not checked.
2550+
2551+
<li>
2552+
<p>Let <var>policy</var> be the <a>combined value</a> with
2553+
`<a http-header><code>Cross-Origin-Resource-Policy</code></a>` and <var>response</var>'s
2554+
<a for=response>header list</a>.
2555+
2556+
<p class=note>This means that `<code>Cross-Origin-Resource-Policy: same-site, same-origin</code>`
2557+
ends up as <b>allowed</b> below as it will never match anything. Two or more
2558+
`<a http-header><code>Cross-Origin-Resource-Policy</code></a>` headers will have the same effect.
2559+
2560+
<li><p>If <var>policy</var> is `<code>same-origin</code>`, then return <b>blocked</b>.
2561+
2562+
<li>
2563+
<p>If the following are true
2564+
2565+
<ul class=brief>
2566+
<li><var>request</var>'s <a for=request>origin</a>'s <a for=url>host</a> is <a>same site</a> with
2567+
<var>request</var>'s <a for=request>current url</a>'s <a for=url>host</a>
2568+
<li><var>request</var>'s <a for=request>origin</a>'s <a for=url>scheme</a> is
2569+
"<code>https</code>" or <var>response</var>'s <a for=response>HTTPS state</a> is
2570+
"<code>none</code>"
2571+
</ul>
2572+
2573+
<p>then return <b>allowed</b>.
2574+
2575+
<p class=note>This prevents HTTPS responses with
2576+
`<code>Cross-Origin-Resource-Policy: same-site</code>` from being accessed without secure
2577+
transport.
2578+
2579+
<li><p>If <var>policy</var> is `<code>same-site</code>`, then return <b>blocked</b>.
2580+
2581+
<li><p>Return <b>allowed</b>.
2582+
</ol>
2583+
2584+
25202585

25212586
<h2 id=fetching>Fetching</h2>
25222587

@@ -3856,6 +3921,10 @@ Range Requests</cite>. [[HTTP-RANGE]] However, this is not widely supported by b
38563921
<li><p>If <var>httpRequest</var>'s <a for=request>header list</a> <a for="header list">contains</a>
38573922
`<code>Range</code>`, then set <var>response</var>'s <a for=response>range-requested flag</a>.
38583923

3924+
<li><p>If the <i>CORS flag</i> is unset and the <a>cross-origin resource policy check</a> with
3925+
<var>request</var> and <var>response</var> returns <b>blocked</b>, then return a
3926+
<a>network error</a>.
3927+
38593928
<li>
38603929
<p>If <var>response</var>'s <a for=response>status</a> is <code>401</code>, <i>CORS flag</i>
38613930
is unset, <i>credentials flag</i> is set, and <var>request</var>'s <a for=request>window</a> is an
@@ -6554,6 +6623,7 @@ Jeffrey Yasskin,
65546623
Jesse M. Heines,
65556624
Jinho Bang,
65566625
Jochen Eisinger,
6626+
John Wilander,
65576627
Jonas Sicking,
65586628
Jonathan Kingston,
65596629
Jonathan Watt,

0 commit comments

Comments
 (0)