|
| 1 | +<!DOCTYPE qhelp PUBLIC |
| 2 | +"-//Semmle//qhelp//EN" |
| 3 | +"qhelp.dtd"> |
| 4 | +<qhelp> |
| 5 | + |
| 6 | +<overview> |
| 7 | + <p> |
| 8 | + |
| 9 | + A server can send the |
| 10 | + <code>"Access-Control-Allow-Credentials"</code> CORS header to control |
| 11 | + when a browser may send user credentials in Cross-Origin HTTP |
| 12 | + requests. |
| 13 | + |
| 14 | + </p> |
| 15 | + <p> |
| 16 | + |
| 17 | + When the <code>Access-Control-Allow-Credentials</code> header |
| 18 | + is <code>"true"</code>, the <code>Access-Control-Allow-Origin</code> |
| 19 | + header must have a value different from <code>"*"</code> in order to |
| 20 | + make browsers accept the header. Therefore, to allow multiple origins |
| 21 | + for Cross-Origin requests with credentials, the server must |
| 22 | + dynamically compute the value of the |
| 23 | + <code>"Access-Control-Allow-Origin"</code> header. Computing this |
| 24 | + header value from information in the request to the server can |
| 25 | + therefore potentially allow an attacker to control the origins that |
| 26 | + the browser sends credentials to. |
| 27 | + |
| 28 | + </p> |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | +</overview> |
| 33 | + |
| 34 | +<recommendation> |
| 35 | + <p> |
| 36 | + |
| 37 | + When the <code>Access-Control-Allow-Credentials</code> header |
| 38 | + value is <code>"true"</code>, a dynamic computation of the |
| 39 | + <code>Access-Control-Allow-Origin</code> header must involve |
| 40 | + sanitization if it relies on user-controlled input. |
| 41 | + |
| 42 | + |
| 43 | + </p> |
| 44 | + <p> |
| 45 | + |
| 46 | + Since the <code>"null"</code> origin is easy to obtain for an |
| 47 | + attacker, it is never safe to use <code>"null"</code> as the value of |
| 48 | + the <code>Access-Control-Allow-Origin</code> header when the |
| 49 | + <code>Access-Control-Allow-Credentials</code> header value is |
| 50 | + <code>"true"</code>. |
| 51 | + |
| 52 | + </p> |
| 53 | +</recommendation> |
| 54 | + |
| 55 | +<example> |
| 56 | + <p> |
| 57 | + |
| 58 | + In the example below, the server allows the browser to send |
| 59 | + user credentials in a Cross-Origin request. The request header |
| 60 | + <code>origins</code> controls the allowed origins for such a |
| 61 | + Cross-Origin request. |
| 62 | + |
| 63 | + </p> |
| 64 | + |
| 65 | + <sample src="examples/CorsBad.cs"/> |
| 66 | + |
| 67 | + <p> |
| 68 | + |
| 69 | + This is not secure, since an attacker can choose the value of |
| 70 | + the <code>origin</code> request header to make the browser send |
| 71 | + credentials to their own server. The use of a allowlist containing |
| 72 | + allowed origins for the Cross-Origin request fixes the issue: |
| 73 | + |
| 74 | + </p> |
| 75 | + |
| 76 | + <sample src="examples/CorsGood.cs"/> |
| 77 | +</example> |
| 78 | + |
| 79 | +<references> |
| 80 | + <li>Mozilla Developer Network: <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin">CORS, Access-Control-Allow-Origin</a>.</li> |
| 81 | + <li>Mozilla Developer Network: <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Credentials">CORS, Access-Control-Allow-Credentials</a>.</li> |
| 82 | + <li>PortSwigger: <a href="http://blog.portswigger.net/2016/10/exploiting-cors-misconfigurations-for.html">Exploiting CORS Misconfigurations for Bitcoins and Bounties</a></li> |
| 83 | + <li>W3C: <a href="https://w3c.github.io/webappsec-cors-for-developers/#resources">CORS for developers, Advice for Resource Owners</a></li> |
| 84 | +</references> |
| 85 | +</qhelp> |
0 commit comments