Skip to content

Commit 0d6f5f2

Browse files
committed
More wildcards in CORS when used without credentials
Fixes #251 and fixes #252.
1 parent f080d2f commit 0d6f5f2

File tree

2 files changed

+130
-26
lines changed

2 files changed

+130
-26
lines changed

Overview.html

+65-13
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,8 @@ <h4 id="terminology-headers"><span class="secno">3.1.2 </span>Headers</h4>
456456
<p>and whose <a href="#concept-header-value" title="concept-header-value">value</a>,
457457
<a href="#concept-header-parse" title="concept-header-parse">once parsed</a>, is not a failure.
458458

459+
<p>A <dfn id="cors-non-wildcard-request-header-name">CORS non-wildcard request-header name</dfn> is `<code title="">Authorization</code>`.
460+
459461
<p>A <dfn id="cors-safelisted-response-header-name">CORS-safelisted response-header name</dfn>, given a
460462
<a href="#concept-response-cors-exposed-header-name-list" title="concept-response-cors-exposed-header-name-list">CORS-exposed header-name list</a>
461463
<var>list</var>, is a <a href="#concept-header" title="concept-header">header</a>
@@ -1857,12 +1859,14 @@ <h4 id="http-new-header-syntax"><span class="secno">4.2.4 </span>HTTP new-header
18571859
<pre>Access-Control-Request-Method = <a class="external" data-anolis-spec="http" href="https://tools.ietf.org/html/rfc7230#section-3.1.1">method</a>
18581860
Access-Control-Request-Headers = #<a class="external" data-anolis-spec="http" href="https://tools.ietf.org/html/rfc7230#section-3.2">field-name</a>
18591861

1860-
Access-Control-Allow-Origin = origin-or-null / "*"
1862+
wilrdcard = "*"
1863+
Access-Control-Allow-Origin = origin-or-null / wildcard
18611864
Access-Control-Allow-Credentials = %x74.72.75.65 ; "true", case-sensitive
1862-
Access-Control-Expose-Headers = #<a class="external" data-anolis-spec="http" href="https://tools.ietf.org/html/rfc7230#section-3.2">field-name</a>
1865+
Access-Control-Expose-Headers = field-name-or-wildcard
1866+
field-name-or-wildcard = <a class="external" data-anolis-spec="http" href="https://tools.ietf.org/html/rfc7230#section-3.2">field-name</a> / wildcard
18631867
Access-Control-Max-Age = <a class="external" data-anolis-spec="http-caching" href="https://tools.ietf.org/html/rfc7234#section-1.2.1">delta-seconds</a>
1864-
Access-Control-Allow-Methods = #<a class="external" data-anolis-spec="http" href="https://tools.ietf.org/html/rfc7230#section-3.1.1">method</a>
1865-
Access-Control-Allow-Headers = #<a class="external" data-anolis-spec="http" href="https://tools.ietf.org/html/rfc7230#section-3.2">field-name</a></pre>
1868+
Access-Control-Allow-Methods = #<a class="external" data-anolis-spec="http" href="https://tools.ietf.org/html/rfc7230#section-3.1.1">method</a> / wildcard
1869+
Access-Control-Allow-Headers = #field-name-or-wildcard</pre>
18661870

18671871

18681872
<h4 id="cors-protocol-and-credentials"><span class="secno">4.2.5 </span>CORS protocol and credentials</h4>
@@ -1964,6 +1968,13 @@ <h4 id="cors-protocol-and-credentials"><span class="secno">4.2.5 </span>CORS pro
19641968
<td>`<code>true</code>` is (byte) case-sensitive.
19651969
</table>
19661970

1971+
<p>Similarly, `<a href="#http-access-control-expose-headers"><code title="http-access-control-expose-headers">Access-Control-Expose-Headers</code></a>`,
1972+
`<a href="#http-access-control-allow-methods"><code title="http-access-control-allow-methods">Access-Control-Allow-Methods</code></a>`, and
1973+
`<a href="#http-access-control-allow-headers"><code title="http-access-control-allow-headers">Access-Control-Allow-Headers</code></a>` response
1974+
headers can only use `<code>*</code>` as value when <a href="#concept-request" title="concept-request">request</a>'s
1975+
<a href="#concept-request-credentials-mode" title="concept-request-credentials-mode">credentials mode</a> is not "<code>include</code>".
1976+
1977+
19671978
<h4 id="cors-protocol-examples"><span class="secno">4.2.6 </span>Examples</h4>
19681979

19691980
<div class="example">
@@ -2452,13 +2463,29 @@ <h3 id="main-fetch"><span class="secno">5.1 </span>Main fetch</h3>
24522463
run these substeps:
24532464

24542465
<ol>
2455-
<li><p>If <var>request</var>'s
2456-
<a href="#concept-request-response-tainting" title="concept-request-response-tainting">response tainting</a> is
2457-
"<code title="">cors</code>", then set <var>response</var>'s
2458-
<a href="#concept-response-cors-exposed-header-name-list" title="concept-response-cors-exposed-header-name-list">CORS-exposed header-name list</a>
2459-
to the result of <a href="#concept-header-parse" title="concept-header-parse">parsing</a>
2460-
`<a href="#http-access-control-expose-headers"><code title="http-access-control-expose-headers">Access-Control-Expose-Headers</code></a>` in
2461-
<var>response</var>'s <a href="#concept-response-header-list" title="concept-response-header-list">header list</a>.
2466+
<li>
2467+
<p>If <var>request</var>'s
2468+
<a href="#concept-request-response-tainting" title="concept-request-response-tainting">response tainting</a> is
2469+
"<code title="">cors</code>", then run these substeps:</p>
2470+
2471+
<ol>
2472+
<li><p>Let <var>headerNames</var> be the result <a href="#concept-header-parse" title="concept-header-parse">parsing</a>
2473+
`<a href="#http-access-control-expose-headers"><code title="http-access-control-expose-headers">Access-Control-Expose-Headers</code></a>` in
2474+
<var>response</var>'s <a href="#concept-response-header-list" title="concept-response-header-list">header list</a>.
2475+
2476+
<li><p>If <var>headerNames</var> contains `<code title="">*</code>` and <var>request</var>'s
2477+
<a href="#concept-request-credentials-mode" title="concept-request-credentials-mode">credentials mode</a> is not
2478+
"<code>include</code>", then set <var>response</var>'s
2479+
<a href="#concept-response-cors-exposed-header-name-list" title="concept-response-cors-exposed-header-name-list">CORS-exposed header-name list</a>
2480+
to all unique <a href="#concept-header" title="concept-header">header</a>
2481+
<a href="#concept-header-name" title="concept-header-name">names</a> in <var>response</var>'s
2482+
<a href="#concept-response-header-list" title="concept-response-header-list">header list</a>.</li>
2483+
2484+
<li><p>Otherwise, if <var>headerNames</var> does <em>not</em> contain `<code title="">*</code>`,
2485+
then set <var>response</var>'s
2486+
<a href="#concept-response-cors-exposed-header-name-list" title="concept-response-cors-exposed-header-name-list">CORS-exposed header-name list</a>
2487+
to <var>headerNames</var>.</p>
2488+
</ol>
24622489

24632490
<li>
24642491
<p>Set <var>response</var> to the following
@@ -3630,9 +3657,21 @@ <h3 id="cors-preflight-fetch"><span class="secno">5.7 </span>CORS-preflight fetc
36303657
<li><p>If either <var>methods</var> or <var>headerNames</var> is failure,
36313658
return a <a href="#concept-network-error" title="concept-network-error">network error</a>.
36323659

3660+
<li><p>If <var>methods</var> is `<code>*</code>` or <var>headerNames</var> contains
3661+
`<code>*</code>`, and <var>request</var>'s
3662+
<a href="#concept-request-credentials-mode" title="concept-request-credentials-mode">credentials mode</a> is "<code>include</code>",
3663+
then return a <a href="#concept-network-error" title="concept-network-error">network error</a>.
3664+
36333665
<li>
3634-
<p>If <var>methods</var> is null and <var>request</var>'s <a href="#use-cors-preflight-flag">use-CORS-preflight flag</a>
3635-
is set, set <var>methods</var> to <var>request</var>'s
3666+
<p>If one of the following is true
3667+
3668+
<ul class="brief">
3669+
<li><var>methods</var> is null and <var>request</var>'s <a href="#use-cors-preflight-flag">use-CORS-preflight flag</a> is
3670+
set
3671+
<li><var>methods</var> is `<code>*</code>`
3672+
</ul>
3673+
3674+
<p>then set <var>methods</var> to a new list containing <var>request</var>'s
36363675
<a href="#concept-request-method" title="concept-request-method">method</a>.
36373676

36383677
<p class="note no-backref">This ensures that a <a href="#cors-preflight-fetch-0">CORS-preflight fetch</a> that
@@ -3643,6 +3682,18 @@ <h3 id="cors-preflight-fetch"><span class="secno">5.7 </span>CORS-preflight fetc
36433682
is not in <var>methods</var> and is not a <a href="#simple-method">simple method</a>, return a
36443683
<a href="#concept-network-error" title="concept-network-error">network error</a>.
36453684

3685+
<li><p>If one of <var>request</var>'s
3686+
<a href="#concept-request-header-list" title="concept-request-header-list">header list</a>'s
3687+
<a href="#concept-header-name" title="concept-header-name">names</a> is a
3688+
<a href="#cors-non-wildcard-request-header-name">CORS non-wildcard request-header name</a> and is not in <var>headerNames</var>, then
3689+
return a <a href="#concept-network-error" title="concept-network-error">network error</a>.
3690+
3691+
<li><p>If <var>headerNames</var> contains `<code>*</code>`, then remove all occurances of
3692+
`<code>*</code>` from <var>headerNames</var> and append all unique
3693+
<a href="#concept-header" title="concept-header">header</a> <a href="#concept-header-name" title="concept-header-name">names</a> from
3694+
<var>request</var>'s <a href="#concept-request-header-list" title="concept-request-header-list">header list</a> to
3695+
<var>headerNames</var>.
3696+
36463697
<li><p>If one of <var>request</var>'s
36473698
<a href="#concept-request-header-list" title="concept-request-header-list">header list</a>'
36483699
<a href="#concept-header-name" title="concept-header-name">names</a> is not in <var>headerNames</var> and
@@ -5522,6 +5573,7 @@ <h2 class="no-num" id="acknowledgments">Acknowledgments</h2>
55225573
Clement Pellerin,
55235574
Collin Jackson,
55245575
Daniel Robertson,
5576+
Daniel Veditz,
55255577
David Håsäther,
55265578
David Orchard,
55275579
Domenic Denicola,

Overview.src.html

+65-13
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,8 @@ <h4 id=terminology-headers>Headers</h4>
384384
<p>and whose <span title=concept-header-value>value</span>,
385385
<span title=concept-header-parse>once parsed</span>, is not a failure.
386386

387+
<p>A <dfn>CORS non-wildcard request-header name</dfn> is `<code title>Authorization</code>`.
388+
387389
<p>A <dfn>CORS-safelisted response-header name</dfn>, given a
388390
<span title=concept-response-cors-exposed-header-name-list>CORS-exposed header-name list</span>
389391
<var>list</var>, is a <span title=concept-header>header</span>
@@ -1785,12 +1787,14 @@ <h4 id=http-new-header-syntax>HTTP new-header syntax</h4>
17851787
<pre>Access-Control-Request-Method = <span data-anolis-spec=http>method</span>
17861788
Access-Control-Request-Headers = #<span data-anolis-spec=http>field-name</span>
17871789

1788-
Access-Control-Allow-Origin = origin-or-null / "*"
1790+
wilrdcard = "*"
1791+
Access-Control-Allow-Origin = origin-or-null / wildcard
17891792
Access-Control-Allow-Credentials = %x74.72.75.65 ; "true", case-sensitive
1790-
Access-Control-Expose-Headers = #<span data-anolis-spec=http>field-name</span>
1793+
Access-Control-Expose-Headers = field-name-or-wildcard
1794+
field-name-or-wildcard = <span data-anolis-spec=http>field-name</span> / wildcard
17911795
Access-Control-Max-Age = <span data-anolis-spec=http-caching>delta-seconds</span>
1792-
Access-Control-Allow-Methods = #<span data-anolis-spec=http>method</span>
1793-
Access-Control-Allow-Headers = #<span data-anolis-spec=http>field-name</span></pre>
1796+
Access-Control-Allow-Methods = #<span data-anolis-spec=http>method</span> / wildcard
1797+
Access-Control-Allow-Headers = #field-name-or-wildcard</pre>
17941798

17951799

17961800
<h4>CORS protocol and credentials</h4>
@@ -1892,6 +1896,13 @@ <h4>CORS protocol and credentials</h4>
18921896
<td>`<code>true</code>` is (byte) case-sensitive.
18931897
</table>
18941898

1899+
<p>Similarly, `<code title=http-access-control-expose-headers>Access-Control-Expose-Headers</code>`,
1900+
`<code title=http-access-control-allow-methods>Access-Control-Allow-Methods</code>`, and
1901+
`<code title=http-access-control-allow-headers>Access-Control-Allow-Headers</code>` response
1902+
headers can only use `<code>*</code>` as value when <span title=concept-request>request</span>'s
1903+
<span title=concept-request-credentials-mode>credentials mode</span> is not "<code>include</code>".
1904+
1905+
18951906
<h4 id=cors-protocol-examples>Examples</h4>
18961907

18971908
<div class="example">
@@ -2380,13 +2391,29 @@ <h3>Main fetch</h3>
23802391
run these substeps:
23812392

23822393
<ol>
2383-
<li><p>If <var>request</var>'s
2384-
<span title=concept-request-response-tainting>response tainting</span> is
2385-
"<code title>cors</code>", then set <var>response</var>'s
2386-
<span title=concept-response-cors-exposed-header-name-list>CORS-exposed header-name list</span>
2387-
to the result of <span title=concept-header-parse>parsing</span>
2388-
`<code title=http-access-control-expose-headers>Access-Control-Expose-Headers</code>` in
2389-
<var>response</var>'s <span title=concept-response-header-list>header list</span>.
2394+
<li>
2395+
<p>If <var>request</var>'s
2396+
<span title=concept-request-response-tainting>response tainting</span> is
2397+
"<code title>cors</code>", then run these substeps:</p>
2398+
2399+
<ol>
2400+
<li><p>Let <var>headerNames</var> be the result <span title=concept-header-parse>parsing</span>
2401+
`<code title=http-access-control-expose-headers>Access-Control-Expose-Headers</code>` in
2402+
<var>response</var>'s <span title=concept-response-header-list>header list</span>.
2403+
2404+
<li><p>If <var>headerNames</var> contains `<code title>*</code>` and <var>request</var>'s
2405+
<span title=concept-request-credentials-mode>credentials mode</span> is not
2406+
"<code>include</code>", then set <var>response</var>'s
2407+
<span title=concept-response-cors-exposed-header-name-list>CORS-exposed header-name list</span>
2408+
to all unique <span title=concept-header>header</span>
2409+
<span title=concept-header-name>names</span> in <var>response</var>'s
2410+
<span title=concept-response-header-list>header list</span>.</p></li>
2411+
2412+
<li><p>Otherwise, if <var>headerNames</var> does <em>not</em> contain `<code title>*</code>`,
2413+
then set <var>response</var>'s
2414+
<span title=concept-response-cors-exposed-header-name-list>CORS-exposed header-name list</span>
2415+
to <var>headerNames</var>.</p>
2416+
</ol>
23902417

23912418
<li>
23922419
<p>Set <var>response</var> to the following
@@ -3558,9 +3585,21 @@ <h3>CORS-preflight fetch</h3>
35583585
<li><p>If either <var>methods</var> or <var>headerNames</var> is failure,
35593586
return a <span title=concept-network-error>network error</span>.
35603587

3588+
<li><p>If <var>methods</var> is `<code>*</code>` or <var>headerNames</var> contains
3589+
`<code>*</code>`, and <var>request</var>'s
3590+
<span title=concept-request-credentials-mode>credentials mode</span> is "<code>include</code>",
3591+
then return a <span title=concept-network-error>network error</span>.
3592+
35613593
<li>
3562-
<p>If <var>methods</var> is null and <var>request</var>'s <span>use-CORS-preflight flag</span>
3563-
is set, set <var>methods</var> to <var>request</var>'s
3594+
<p>If one of the following is true
3595+
3596+
<ul class=brief>
3597+
<li><var>methods</var> is null and <var>request</var>'s <span>use-CORS-preflight flag</span> is
3598+
set
3599+
<li><var>methods</var> is `<code>*</code>`
3600+
</ul>
3601+
3602+
<p>then set <var>methods</var> to a new list containing <var>request</var>'s
35643603
<span title=concept-request-method>method</span>.
35653604

35663605
<p class="note no-backref">This ensures that a <span>CORS-preflight fetch</span> that
@@ -3571,6 +3610,18 @@ <h3>CORS-preflight fetch</h3>
35713610
is not in <var>methods</var> and is not a <span>simple method</span>, return a
35723611
<span title=concept-network-error>network error</span>.
35733612

3613+
<li><p>If one of <var>request</var>'s
3614+
<span title=concept-request-header-list>header list</span>'s
3615+
<span title=concept-header-name>names</span> is a
3616+
<span>CORS non-wildcard request-header name</span> and is not in <var>headerNames</var>, then
3617+
return a <span title=concept-network-error>network error</span>.
3618+
3619+
<li><p>If <var>headerNames</var> contains `<code>*</code>`, then remove all occurances of
3620+
`<code>*</code>` from <var>headerNames</var> and append all unique
3621+
<span title=concept-header>header</span> <span title=concept-header-name>names</span> from
3622+
<var>request</var>'s <span title=concept-request-header-list>header list</span> to
3623+
<var>headerNames</var>.
3624+
35743625
<li><p>If one of <var>request</var>'s
35753626
<span title=concept-request-header-list>header list</span>'
35763627
<span title=concept-header-name>names</span> is not in <var>headerNames</var> and
@@ -5358,6 +5409,7 @@ <h2 class=no-num>Acknowledgments</h2>
53585409
Clement Pellerin,
53595410
Collin Jackson,
53605411
Daniel Robertson,
5412+
Daniel Veditz,
53615413
David H&aring;s&auml;ther,
53625414
David Orchard,
53635415
Domenic Denicola,

0 commit comments

Comments
 (0)