Skip to content

Commit ce08dff

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: * web-platform-tests/wpt#11171 * web-platform-tests/wpt#11427 * web-platform-tests/wpt#11428 Follow-up: #760. Fixes #687.
1 parent 2f3d04d commit ce08dff

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
@@ -2517,6 +2517,58 @@ 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">A cross-origin response redirecting to a response that is
2547+
<a>same origin</a> or <a>same site</a> with the initial request and has a
2548+
`<a http-header><code>Cross-Origin-Resource-Policy</code></a>` header specified, does not affect
2549+
anything. I.e., <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><p>If <var>request</var>'s <a for=request>origin</a>'s <a for=url>host</a> is <a>same site</a>
2563+
with <var>request</var>'s <a for=request>current url</a>'s <a for=url>host</a>, then return
2564+
<b>allowed</b>.
2565+
2566+
<li><p>If <var>policy</var> is `<code>same-site</code>`, then return <b>blocked</b>.
2567+
2568+
<li><p>Return <b>allowed</b>.
2569+
</ol>
2570+
2571+
25202572

25212573
<h2 id=fetching>Fetching</h2>
25222574

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

3905+
<li><p>If the <i>CORS flag</i> is unset and the <a>cross-origin resource policy check</a> with
3906+
<var>request</var> and <var>response</var> returns <b>blocked</b>, then return a
3907+
<a>network error</a>.
3908+
38533909
<li>
38543910
<p>If <var>response</var>'s <a for=response>status</a> is <code>401</code>, <i>CORS flag</i>
38553911
is unset, <i>credentials flag</i> is set, and <var>request</var>'s <a for=request>window</a> is an
@@ -6548,6 +6604,7 @@ Jeffrey Yasskin,
65486604
Jesse M. Heines,
65496605
Jinho Bang,
65506606
Jochen Eisinger,
6607+
John Wilander,
65516608
Jonas Sicking,
65526609
Jonathan Kingston,
65536610
Jonathan Watt,

0 commit comments

Comments
 (0)