Skip to content

Commit 791a7e2

Browse files
committed
Updated qhelp for cors permissive configuration
1 parent 2baca58 commit 791a7e2

File tree

1 file changed

+47
-45
lines changed

1 file changed

+47
-45
lines changed

javascript/ql/src/Security/CWE-942/CorsPermissiveConfiguration.qhelp

Lines changed: 47 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,69 +3,71 @@
33
"qhelp.dtd">
44
<qhelp>
55

6-
<overview>
7-
<p>
6+
<overview>
7+
<p>
88

9-
A server can use <code>CORS</code> (Cross-Origin Resource Sharing) to relax the
10-
restrictions imposed by the <code>SOP</code> (Same-Origin Policy), allowing controlled, secure
11-
cross-origin requests when necessary.
9+
A server can use CORS (Cross-Origin Resource Sharing) to relax the
10+
restrictions imposed by the Same-Origin Policy, allowing controlled, secure
11+
cross-origin requests when necessary.
1212

13-
A server with an overly permissive <code>CORS</code> configuration may inadvertently
14-
expose sensitive data or lead to <code>CSRF</code> which is an attack that allows attackers to trick
15-
users into performing unwanted operations in websites they're authenticated to.
13+
</p>
14+
<p>
1615

17-
</p>
16+
A server with an overly permissive CORS configuration may inadvertently
17+
expose sensitive data or enable CSRF attacks, which allow attackers to trick
18+
users into performing unwanted operations on websites they're authenticated to.
1819

19-
</overview>
20+
</p>
21+
</overview>
2022

21-
<recommendation>
22-
<p>
23+
<recommendation>
24+
<p>
2325

24-
When the <code>origin</code> is set to <code>true</code>, it signifies that the server
25-
is accepting requests from <code>any</code> origin, potentially exposing the system to
26-
CSRF attacks. This can be fixed using <code>false</code> as origin value or using a whitelist.
26+
When the <code>origin</code> is set to <code>true</code>, the server
27+
accepts requests from any origin, potentially exposing the system to
28+
CSRF attacks. Use <code>false</code> as the origin value or implement a whitelist
29+
of allowed origins instead.
2730

28-
</p>
29-
<p>
31+
</p>
32+
<p>
3033

31-
On the other hand, if the <code>origin</code> is
32-
set to <code>null</code>, it can be exploited by an attacker to deceive a user into making
33-
requests from a <code>null</code> origin form, often hosted within a sandboxed iframe.
34+
When the <code>origin</code> is set to <code>null</code>, it can be
35+
exploited by an attacker who can deceive a user into making
36+
requests from a <code>null</code> origin, often hosted within a sandboxed iframe.
3437

35-
</p>
38+
</p>
39+
<p>
3640

37-
<p>
41+
If the <code>origin</code> value is user-controlled, ensure that the data
42+
is properly sanitized and validated against a whitelist of allowed origins.
3843

39-
If the <code>origin</code> value is user controlled, make sure that the data
40-
is properly sanitized.
44+
</p>
45+
</recommendation>
4146

42-
</p>
43-
</recommendation>
47+
<example>
48+
<p>
4449

45-
<example>
46-
<p>
50+
In the following example, <code>server_1</code> accepts requests from any origin
51+
because the value of <code>origin</code> is set to <code>true</code>.
52+
<code>server_2</code> uses user-controlled data for the origin without validation.
4753

48-
In the example below, the <code>server_1</code> accepts requests from any origin
49-
since the value of <code>origin</code> is set to <code>true</code>.
50-
And <code>server_2</code>'s origin is user-controlled.
54+
</p>
5155

52-
</p>
56+
<sample src="examples/CorsPermissiveConfigurationBad.js"/>
5357

54-
<sample src="examples/CorsPermissiveConfigurationBad.js"/>
58+
<p>
5559

56-
<p>
60+
To fix these issues, <code>server_1</code> uses a restrictive CORS configuration
61+
that is not vulnerable to CSRF attacks. <code>server_2</code> properly validates
62+
user-controlled data against a whitelist before using it.
5763

58-
In the example below, the <code>server_1</code> CORS is restrictive so it's not
59-
vulnerable to CSRF attacks. And <code>server_2</code>'s is using properly sanitized
60-
user-controlled data.
64+
</p>
6165

62-
</p>
66+
<sample src="examples/CorsPermissiveConfigurationGood.js"/>
67+
</example>
6368

64-
<sample src="examples/CorsPermissiveConfigurationGood.js"/>
65-
</example>
66-
67-
<references>
68-
<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>
69-
<li>W3C: <a href="https://w3c.github.io/webappsec-cors-for-developers/#resources">CORS for developers, Advice for Resource Owners</a></li>
70-
</references>
69+
<references>
70+
<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>
71+
<li>W3C: <a href="https://w3c.github.io/webappsec-cors-for-developers/#resources">CORS for developers, Advice for Resource Owners</a>.</li>
72+
</references>
7173
</qhelp>

0 commit comments

Comments
 (0)