Skip to content

Commit f31e50a

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 ffbaefb commit f31e50a

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

fetch.bs

+57
Original file line numberDiff line numberDiff line change
@@ -2514,6 +2514,58 @@ run these steps:</p>
25142514
</ol>
25152515

25162516

2517+
<h3 id=cross-origin-resource-policy-header>`<code>Cross-Origin-Resource-Policy</code>` header</h3>
2518+
2519+
<p>The
2520+
`<dfn export http-header id=http-cross-origin-resource-policy><code>Cross-Origin-Resource-Policy</code></dfn>`
2521+
response <a for=/>header</a> can be used to require checking a <a for=/>request</a>'s
2522+
<a for=request>current url</a>'s <a for=url>origin</a> against a <a for=/>request</a>'s
2523+
<a for=request>origin</a> when <a for=/>request</a>'s <a for=request>mode</a> is
2524+
"<code>no-cors</code>".
2525+
2526+
<p>Its <a for=header>value</a> <a>ABNF</a>:
2527+
2528+
<pre>
2529+
Cross-Origin-Resource-Policy = %x73.61.6D.65 / %x73.61.6D.65.2D.73.69.74.65 ; "same" / "same-site", case-sensitive</pre>
2530+
2531+
<p>To perform a <dfn>cross-origin resource policy check</dfn>, given a <var>request</var> and
2532+
<var>response</var>, run these steps:</p>
2533+
2534+
<ol>
2535+
<li><p>If <var>request</var>'s <a for=request>mode</a> is not "<code>no-cors</code>", then return
2536+
<b>allowed</b>.
2537+
2538+
<li>
2539+
<p>If <var>request</var>'s <a for=request>origin</a> is <a>same origin</a> with
2540+
<var>request</var>'s <a for=request>current url</a>'s <a for=url>origin</a>, then return
2541+
<b>allowed</b>.
2542+
2543+
<p class="note no-backref">A cross-origin response redirecting to a response that is
2544+
<a>same origin</a> or <a>same site</a> with the initial request and has a
2545+
`<a http-header><code>Cross-Origin-Resource-Policy</code></a>` header specified, does not affect
2546+
anything. I.e., <var>request</var>'s <a for=request>tainted origin flag</a> is not checked.
2547+
2548+
<li>
2549+
<p>Let <var>policy</var> be the <a>combined value</a> with
2550+
`<a http-header><code>Cross-Origin-Resource-Policy</code></a>` and <var>response</var>'s
2551+
<a for=response>header list</a>.
2552+
2553+
<p class=note>This means that `<code>Cross-Origin-Resource-Policy: same-site, same</code>` ends up
2554+
as <b>allowed</b> below as it will never match anything. Two or more
2555+
`<a http-header><code>Cross-Origin-Resource-Policy</code></a>` headers will have the same effect.
2556+
2557+
<li><p>If <var>policy</var> is `<code>same</code>`, then return <b>blocked</b>.
2558+
2559+
<li><p>If <var>request</var>'s <a for=request>origin</a>'s <a for=url>host</a> is <a>same site</a>
2560+
with <var>request</var>'s <a for=request>current url</a>'s <a for=url>host</a>, then return
2561+
<b>allowed</b>.
2562+
2563+
<li><p>If <var>policy</var> is `<code>same-site</code>`, then return <b>blocked</b>.
2564+
2565+
<li><p>Return <b>allowed</b>.
2566+
</ol>
2567+
2568+
25172569

25182570
<h2 id=fetching>Fetching</h2>
25192571

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

3892+
<li><p>If the <i>CORS flag</i> is unset and the <a>cross-origin resource policy check</a> with
3893+
<var>request</var> and <var>response</var> returns <b>blocked</b>, then return a
3894+
<a>network error</a>.
3895+
38403896
<li>
38413897
<p>If <var>response</var>'s <a for=response>status</a> is <code>401</code>, <i>CORS flag</i>
38423898
is unset, <i>credentials flag</i> is set, and <var>request</var>'s <a for=request>window</a> is an
@@ -6535,6 +6591,7 @@ Jeffrey Yasskin,
65356591
Jesse M. Heines,
65366592
Jinho Bang,
65376593
Jochen Eisinger,
6594+
John Wilander,
65386595
Jonas Sicking,
65396596
Jonathan Kingston,
65406597
Jonathan Watt,

0 commit comments

Comments
 (0)