Skip to content

Commit

Permalink
Define Cross-Origin-Resource-Policy response header
Browse files Browse the repository at this point in the history
This header makes it easier for sites to block unwanted "no-cors" cross-origin requests.

Tests: ...

Fixes #687.
  • Loading branch information
annevk committed May 29, 2018
1 parent bd9b4e3 commit 7ee7a08
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions fetch.bs
Original file line number Diff line number Diff line change
Expand Up @@ -2455,6 +2455,64 @@ run these steps:</p>
</ol>


<h3 id=cross-origin-resource-policy-header>`<code>Cross-Origin-Resource-Policy</code>` header</h3>

<p>The
`<dfn export http-header id=http-cross-origin-resource-policy><code>Cross-Origin-Resource-Policy</code></dfn>`
response <a for=/>header</a> can be used to require checking a <a for=/>request</a>'s
<a for=request>current url</a>'s <a for=url>origin</a> against a <a for=/>request</a>'s
<a for=request>origin</a> when <a for=/>request</a>'s <a for=request>mode</a> is
"<code>no-cors</code>".

<p>Its <a for=header>value</a> <a>ABNF</a>:

<pre>
Cross-Origin-Resource-Policy = %x73.61.6D.65 / %x73.61.6D.65.2D.73.69.74.65 ; "same" / "same-site"; case-sensitive</pre>

<p>To perform a <dfn>cross-origin resource policy check</dfn>, given a <var>request</var> and
<var>response</var>, run these steps:</p>

<ol>
<li><p>If <var>request</var>'s <a for=request>mode</a> is not "<code>no-cors</code>", then return
<b>allowed</b>.

<li>
<p>If <var>request</var>'s <a for=request>origin</a> is <a>same origin</a> with
<var>request</var>'s <a for=request>current url</a>'s <a for=url>origin</a>, then return
<b>allowed</b>.

<p class=note>A cross-origin response redirecting to a same or same-site resource with the
`<a http-header><code>Cross-Origin-Resource-Policy</code></a>` header specified does not affect
anything.
<!-- We could make this have an effect if we fix https://github.com/whatwg/fetch/pull/594 first,
but even then we normally do not let this have any effect for "no-cors" so it would be
somewhat inconsistent if it did here, but might still be better... -->

<li><p>Let <var>policy</var> be the <a>combined value</a> with
`<a http-header><code>Cross-Origin-Resource-Policy</code></a>` and <var>response</var>'s
<a for=response>header list</a>.

<li><p>If <var>policy</var> is `<code>same</code>`, then return <b>blocked</b>.

<li>
<p>If <var>policy</var> is `<code>same-site</code>` and neither of the following is true

<ul class=brief>
<li><p><var>request</var>'s <a for=request>origin</a>'s <a for=origin>host</a>
<a>is a registrable domain suffix of or is equal to</a> <var>request</var>'s
<a for=request>current url</a>'s <a for=url>host</a>

<li><p><var>request</var>'s <a for=request>current url</a>'s <a for=url>host</a>
<a>is a registrable domain suffix of or is equal to</a> <var>request</var>'s
<a for=request>origin</a>'s <a for=origin>host</a>
</ul>

<p>then return <b>blocked</b>

<li><p>Return <b>allowed</b>.
</ol>



<h2 id=fetching>Fetching</h2>

Expand Down Expand Up @@ -3751,6 +3809,9 @@ Range Requests</cite>. [[HTTP-RANGE]] However, this is not widely supported by b
</ol>
</ol>

<li><p>If the <a>cross-origin resource policy check</a> with <var>request</var> and
<var>response</var> returns <b>blocked</b>, then return a <a>network error</a>.

<li>
<p>If <var>response</var>'s <a for=response>status</a> is <code>401</code>, <i>CORS flag</i>
is unset, <i>credentials flag</i> is set, and <var>request</var>'s <a for=request>window</a> is an
Expand Down Expand Up @@ -6390,6 +6451,7 @@ Jeffrey Yasskin,
Jesse M. Heines,
Jinho Bang,
Jochen Eisinger,
John Wilander,
Jonas Sicking,
Jonathan Kingston,
Jonathan Watt,
Expand Down

0 comments on commit 7ee7a08

Please sign in to comment.