Skip to content

Commit a6822f2

Browse files
committed
Integrate CORP and COEP
This is part of the introduction of COEP (whatwg/html#5454). The CORP check now takes COEP into account. Also, responses coming from service workers are checked.
1 parent ab6aa41 commit a6822f2

File tree

1 file changed

+119
-29
lines changed

1 file changed

+119
-29
lines changed

fetch.bs

+119-29
Original file line numberDiff line numberDiff line change
@@ -3165,58 +3165,144 @@ response <a for=/>header</a> can be used to require checking a <a for=/>request<
31653165
Cross-Origin-Resource-Policy = %s"same-origin" / %s"same-site" / %s"cross-origin" ; case-sensitive
31663166
</code></pre>
31673167

3168-
<p>To perform a <dfn>cross-origin resource policy check</dfn>, given a <var>request</var> and
3169-
<var>response</var>, run these steps:</p>
3168+
<p>To perform a <dfn>cross-origin resource policy internal check</dfn>, given a string
3169+
<var>embedder policy value</var>, a <a for=/>request</a> <var>request</var> and
3170+
a <a for=/>response</a> <var>response</var>, run these steps:</p>
31703171

31713172
<ol>
3172-
<li><p>If <var>request</var>'s <a for=request>mode</a> is not "<code>no-cors</code>", then return
3173-
<b>allowed</b>.
3173+
<li><p>Assert: <var>request</var>'s <a for=request>mode</a> is "<code>navigate</code>" or
3174+
"<code>no-cors</code>".
31743175

31753176
<li>
3176-
<p>If <var>request</var>'s <a for=request>origin</a> is <a>same origin</a> with
3177-
<var>request</var>'s <a for=request>current URL</a>'s <a for=url>origin</a>, then return
3178-
<b>allowed</b>.
3177+
<p>If <var>request</var>'s <a for=request>mode</a> is "<code>navigate</code>":
31793178

3180-
<p class="note no-backref">While redirects that carry a
3181-
`<a http-header><code>Cross-Origin-Resource-Policy</code></a>` header are checked, redirects
3182-
without such a header resulting in <var>response</var> do not affect the outcome as the default is
3183-
<b>allowed</b>.
3184-
<!-- This changes with COEP's cross-origin value. -->
3179+
<p class="note no-backref">Only HTML's navigate algorithm uses this check for the
3180+
"<code>navigate</code>" <a for=request>mode</a>, for nested navigations. [[!HTML]]
3181+
3182+
<ol>
3183+
<li>
3184+
<p>Assert: <var>request</var> is for a nested navigation.
3185+
3186+
<p class=XXX>Fix this assertion when
3187+
<a href="https://github.com/whatwg/fetch/pull/948">#948</a> is merged.
3188+
3189+
<li><p>If <var>embedder policy value</var> is "<code>unsafe-none</code>", then return
3190+
<b>allowed</b>.
3191+
</ol>
31853192

31863193
<li>
31873194
<p>Let <var>policy</var> be the result of <a for="header list">getting</a>
31883195
`<a http-header><code>Cross-Origin-Resource-Policy</code></a>` from <var>response</var>'s
31893196
<a for=response>header list</a>.
31903197

31913198
<p class=note>This means that `<code>Cross-Origin-Resource-Policy: same-site, same-origin</code>`
3192-
ends up as <b>allowed</b> below as it will never match anything. Two or more
3199+
ends up as <b>allowed</b> below as it will never match anything, as long as
3200+
<var>embedder policy value</var> is "<code>unsafe-none</code>". Two or more
31933201
`<a http-header><code>Cross-Origin-Resource-Policy</code></a>` headers will have the same effect.
31943202

3195-
<li><p>If <var>policy</var> is `<code>same-origin</code>`, then return <b>blocked</b>.
3203+
<li><p>If <var>policy</var> is null and <var>embedder policy value</var> is
3204+
"<code>require-corp</code>", then set <var>policy</var> to "<code>same-origin</code>".
31963205

31973206
<li>
3198-
<p>If the following are true
3207+
<p>Switch on <var>policy</var>:
31993208

3200-
<ul class=brief>
3201-
<li><var>request</var>'s <a for=request>origin</a> is <a>schemelessly same site</a> with
3202-
<var>request</var>'s <a for=request>current URL</a>'s <a for=url>origin</a>
3203-
<li><var>request</var>'s <a for=request>origin</a>'s <a for=url>scheme</a> is
3204-
"<code>https</code>" or <var>response</var>'s <a for=response>HTTPS state</a> is
3205-
"<code>none</code>"
3206-
</ul>
3209+
<dl class=switch>
3210+
<dt>null
3211+
<dt>"<code>cross-origin</code>"
3212+
<dd><p>Return <b>allowed</b>.
32073213

3208-
<p>then return <b>allowed</b>.
3214+
<dt>"<code>same-origin</code>"
3215+
<dd>
3216+
<p>If <var>request</var>'s <a for=request>origin</a> is <a>same origin</a> with
3217+
<var>request</var>'s <a for=request>current URL</a>'s <a for=url>origin</a>, then return
3218+
<b>allowed</b>.
32093219

3210-
<p class=note>This prevents HTTPS responses with
3211-
`<code>Cross-Origin-Resource-Policy: same-site</code>` from being accessed without secure
3212-
transport.
3220+
<p>Otherwise, return <b>blocked</b>.
32133221

3214-
<li><p>If <var>policy</var> is `<code>same-site</code>`, then return <b>blocked</b>.
3222+
<dt>"<code>same-site</code>"
3223+
<dd>
3224+
<p>If the following are true
32153225

3216-
<li><p>Return <b>allowed</b>.
3226+
<ul class=brief>
3227+
<li><p><var>request</var>'s <a for=request>origin</a> is <a>schemelessly same site</a> with
3228+
<var>request</var>'s <a for=request>current URL</a>'s <a for=url>origin</a>
3229+
3230+
<li><p><var>request</var>'s <a for=request>origin</a>'s <a for=url>scheme</a> is
3231+
"<code>https</code>" or <var>response</var>'s <a for=response>HTTPS state</a> is
3232+
"<code>none</code>"
3233+
</ul>
3234+
3235+
<p>then return <b>allowed</b>.
3236+
3237+
<p>Otherwise, return <b>blocked</b>.
3238+
3239+
<p class=note>`<code>Cross-Origin-Resource-Policy: same-site</code>` does not consider a
3240+
response delivered via a secure transport to match a non-secure requesting origin,
3241+
even if their hosts are otherwise same site. Securely-transported responses will only
3242+
match a securely-transported initiator.
3243+
</dl>
3244+
</ol>
3245+
3246+
<p>To <dfn>queue a cross-origin embedder policy CORP violation report</dfn>, given a <a for=/>request</a>
3247+
<var>request</var> and a string <var>reporting endpoint</var>, run these steps:
3248+
3249+
<ol>
3250+
<li><p>Let <var>serialized url</var> be the result of
3251+
<a lt="serialize a request URL for reporting">serializing a request URL for reporting</a> with
3252+
<var>request</var>.
3253+
3254+
<li>
3255+
<p>Let <var>body</var> be a new object containing the following properties:
3256+
3257+
<table>
3258+
<thead>
3259+
<th>key
3260+
<th>value
3261+
</thead>
3262+
<tbody>
3263+
<tr>
3264+
<td>"<code>type</code>"
3265+
<td>"<code>corp</code>"
3266+
</tr>
3267+
<tr>
3268+
<td>"<code>blocked-url</code>"
3269+
<td><var>serialized url</var>
3270+
</tr>
3271+
</tbody>
3272+
</table>
3273+
3274+
<li><p><a href="https://w3c.github.io/reporting/#queue-report">Queue</a> <var>body</var> as
3275+
"<code>coep</code>" for <var>reporting endpoint</var> on <var>request</var>'s
3276+
<a for=request>client</a>. [[!REPORTING]]
32173277
</ol>
32183278

32193279

3280+
<p>To perform a <dfn>cross-origin resource policy check</dfn>, given a <a for=/>request</a>
3281+
<var>request</var> and a <a for=/>response</a> <var>response</var>, run these steps:</p>
3282+
<ol>
3283+
<li><p>Let <var>embedder policy</var> be <var>request</var>'s <a for=request>client</a>'s
3284+
embedder policy.
3285+
3286+
<li>
3287+
<p>If the <a>cross-origin resource policy internal check</a> with "<code>unsafe-none</code>",
3288+
<var>request</var> and <var>response</var> returns <b>blocked</b>, then return <b>blocked</b>.
3289+
3290+
<p class="note no-backref">This is to queue only COEP related violation reports.
3291+
3292+
<li><p>If the <a>cross-origin resource policy internal check</a> with <var>embedder policy</var>'s
3293+
report only value, <var>request</var> and <var>response</var> returns <b>blocked</b>, then
3294+
<a>queue a cross-origin embedder policy CORP violation report</a> with
3295+
<var>request</var> and <var>embedder policy</var>'s report only reporting endpoint.
3296+
3297+
<li><p>If the <a>cross-origin resource policy internal check</a> with
3298+
<var>embedder policy</var>'s value, <var>request</var> and <var>response</var> returns
3299+
<b>allowed</b>, then return <b>allowed</b>.
3300+
3301+
<li><p><a>Queue a cross-origin embedder policy CORP violation report</a> with <var>request</var>
3302+
and <var>embedder policy</var>'s reporting endpoint.
3303+
3304+
<li><p>Return <b>blocked</b>.
3305+
</ol>
32203306

32213307
<h2 id=fetching>Fetching</h2>
32223308

@@ -3913,6 +3999,10 @@ optional <i>CORS-preflight flag</i>, run these steps:
39133999

39144000
<li><var>request</var>'s <a for=request>redirect mode</a> is not "<code>follow</code>" and
39154001
<var>response</var>'s <a for=response>URL list</a> has more than one item.
4002+
4003+
<li><p><var>request</var>'s <a for=request>response tainting</a> is "<code>opaque</code>" and
4004+
the <a>cross-origin resource policy check</a> with <var>request</var> and <var>response</var>
4005+
returns <b>blocked</b>.
39164006
</ul>
39174007

39184008
<p>then return a <a>network error</a>.
@@ -4533,7 +4623,7 @@ Range Requests</cite>. [[HTTP-RANGE]] However, this is not widely supported by b
45334623
<li><p>If <var>httpRequest</var>'s <a for=request>header list</a> <a for="header list">contains</a>
45344624
`<code>Range</code>`, then set <var>response</var>'s <a for=response>range-requested flag</a>.
45354625

4536-
<li><p>If <var>httpRequest</var>'s <a for=request>response tainting</a> is not "<code>cors</code>"
4626+
<li><p>If <var>httpRequest</var>'s <a for=request>response tainting</a> is "<code>opaque</code>"
45374627
and the <a>cross-origin resource policy check</a> with <var>request</var> and <var>response</var>
45384628
returns <b>blocked</b>, then return a <a>network error</a>.
45394629

0 commit comments

Comments
 (0)