Skip to content

Commit a633bf0

Browse files
committed
Define Cross-Origin-Resource-Policy response header
This header makes it easier for sites to block unwanted "no-cors" cross-origin requests. Tests: ... Fixes #687.
1 parent 794dd54 commit a633bf0

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

fetch.bs

+61
Original file line numberDiff line numberDiff line change
@@ -2437,6 +2437,63 @@ run these steps:</p>
24372437
</ol>
24382438

24392439

2440+
<h3 id=cross-origin-resource-policy-header>`<code>Cross-Origin-Resource-Policy</code>` header</h3>
2441+
2442+
<p>The
2443+
`<dfn export http-header id=http-cross-origin-resource-policy><code>Cross-Origin-Resource-Policy</code></dfn>`
2444+
response <a for=/>header</a> can be used to require checking a <a for=/>request</a>'s
2445+
<a for=request>current url</a>'s <a for=URL>origin</a> against a <a for=/>request</a>'s
2446+
<a for=request>origin</a> when <a for=/>request</a>'s <a for=request>mode</a> is
2447+
"<code>no-cors</code>".
2448+
2449+
<p>Its <a for=header>value</a> <a>ABNF</a>:
2450+
2451+
<pre>
2452+
Cross-Origin-Resource-Policy = %x73.61.6D.65 / %x73.61.6D.65.2D.73.69.74.65 ; "same" / "same-site"; case-sensitive</pre>
2453+
2454+
<p>To perform a <dfn>cross-origin resource policy check</dfn>, given a <var>request</var> and
2455+
<var>response</var>, run these steps:</p>
2456+
2457+
<ol>
2458+
<li><p>If <var>request</var>'s <a for=request>mode</a> is not "<code>no-cors</code>", then return
2459+
<b>allowed</b>.
2460+
2461+
<li>
2462+
<p>If <var>request</var>'s <a for=request>origin</a> is <a>same origin</a> with
2463+
<var>request</var>'s <a for=request>current url</a>'s <a for=URL>origin</a>, then return
2464+
<b>allowed</b>.
2465+
2466+
<p class=note>A cross-origin response redirecting to a same or same-site resource with the
2467+
`<code header>Cross-Origin-Resource-Policy</code>` header specified does not affect anything.
2468+
<!-- We could make this have an effect if we fix https://github.com/whatwg/fetch/pull/594 first,
2469+
but even then we normally do not let this have any effect for "no-cors" so it would be
2470+
somewhat inconsistent if it did here, but might still be better... -->
2471+
2472+
<li><p>Let <var>policy</var> be the <a>combined value</a> with
2473+
`<code header>Cross-Origin-Resource-Policy</code>` and <var>response</var>'s
2474+
<a for=response>header list</a>.
2475+
2476+
<li><p>If <var>policy</var> is `<code>same</code>`, then return <b>blocked</b>.
2477+
2478+
<li>
2479+
<p>If <var>policy</var> is `<code>same-site</code>` and neither of the following is true
2480+
2481+
<ul class=brief>
2482+
<li><p><var>request</var>'s <a for=request>origin</a>'s <a for=origin>host</a>
2483+
<a>is a registrable domain suffix of or is equal to</a> <var>request</var>'s
2484+
<a for=request>current url</a>'s <a for=URL>host</a>
2485+
2486+
<li><p><var>request</var>'s <a for=request>current url</a>'s <a for=URL>host</a>
2487+
<a>is a registrable domain suffix of or is equal to</a> <var>request</var>'s
2488+
<a for=request>origin</a>'s <a for=origin>host</a>
2489+
</ul>
2490+
2491+
<p>then return <b>blocked</b>
2492+
2493+
<li><p>Return <b>allowed</b>.
2494+
</ol>
2495+
2496+
24402497

24412498
<h2 id=fetching>Fetching</h2>
24422499

@@ -3736,6 +3793,9 @@ Range Requests</cite>. [[HTTP-RANGE]] However, this is not widely supported by b
37363793
</ol>
37373794
</ol>
37383795

3796+
<li><p>If the <a>cross-origin resource policy check</a> with <var>request</var> and
3797+
<var>response</var> returns <b>blocked</b>, then return a <a>network error</a>.
3798+
37393799
<li>
37403800
<p>If <var>response</var>'s <a for=response>status</a> is <code>401</code>, <i>CORS flag</i>
37413801
is unset, <i>credentials flag</i> is set, and <var>request</var>'s <a for=request>window</a> is an
@@ -6366,6 +6426,7 @@ Jeffrey Yasskin,
63666426
Jesse M. Heines,
63676427
Jinho Bang,
63686428
Jochen Eisinger,
6429+
John Wilander,
63696430
Jonas Sicking,
63706431
Jonathan Kingston,
63716432
Jonathan Watt,

0 commit comments

Comments
 (0)