You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: javascript/ql/src/Security/CWE-693/InsecureHelmet.qhelp
+42-38Lines changed: 42 additions & 38 deletions
Original file line number
Diff line number
Diff line change
@@ -5,12 +5,14 @@
5
5
<ahref="https://helmetjs.github.io/">Helmet</a> is a collection of middleware functions for securing Express apps. It sets various HTTP headers to guard against common web vulnerabilities.
6
6
7
7
This query detects Helmet misconfigurations that can lead to security vulnerabilities, specifically:
8
+
</p>
8
9
9
-
<ul>
10
-
<li>Disabling frame protection</li>
11
-
<li>Disabling Content Security Policy</li>
12
-
</ul>
10
+
<ul>
11
+
<li>Disabling frame protection</li>
12
+
<li>Disabling Content Security Policy</li>
13
+
</ul>
13
14
15
+
<p>
14
16
Content Security Policy (CSP) helps spot and prevent injection attacks such as Cross-Site Scripting (XSS).
15
17
16
18
Removing frame protections exposes an application to attacks such as clickjacking, where an attacker can trick a user into clicking on a button or link on a targeted page when they intended to click on the page carrying out the attack.
@@ -19,53 +21,55 @@
19
21
<recommendation>
20
22
<p>
21
23
To help mitigate these vulnerabilities, ensure that the following Helmet functions are not disabled, and are configured appropriately to your application:
22
-
<ul>
23
-
<li><code>frameguard</code></li>
24
-
<li><code>contentSecurityPolicy</code></li>
25
-
</ul>
26
24
</p>
25
+
26
+
<ul>
27
+
<li><code>frameguard</code></li>
28
+
<li><code>contentSecurityPolicy</code></li>
29
+
</ul>
27
30
</recommendation>
28
31
<example>
29
32
<p>
30
33
The following code snippet demonstrates Helmet configured in an insecure manner:
31
-
<codeclass="language-javascript">
32
-
const helmet = require('helmet');
33
-
app.use(helmet({
34
-
frameguard: false,
35
-
contentSecurityPolicy: false
36
-
}));
37
-
</code>
38
34
</p>
35
+
36
+
<pre>
37
+
const helmet = require('helmet');
38
+
app.use(helmet({
39
+
frameguard: false,
40
+
contentSecurityPolicy: false
41
+
}));
42
+
</pre>
43
+
39
44
<p>
40
45
In this example, the defaults are used, which enables frame protection and a default Content Security Policy.
46
+
</p>
41
47
42
-
<codeclass="language-javascript">
43
-
app.use(helmet());
44
-
</code>
45
-
46
-
You can also enable a custom Content Security Policy by passing an object to the <code>contentSecurityPolicy</code> key. For example, taken from the <ahref="https://helmetjs.github.io/#content-security-policy">Helmet docs:
48
+
<pre>
49
+
app.use(helmet());
50
+
</pre>
47
51
48
-
<codeclass="language-javascript">
49
-
app.use(
50
-
helmet({
51
-
contentSecurityPolicy: {
52
-
directives: {
53
-
"script-src": ["'self'", "example.com"],
54
-
"style-src": null,
55
-
},
56
-
},
57
-
})
58
-
);
59
-
<code>
60
52
<p>
61
-
53
+
You can also enable a custom Content Security Policy by passing an object to the <code>contentSecurityPolicy</code> key. For example, taken from the <ahref="https://helmetjs.github.io/#content-security-policy">Helmet docs</a>:
0 commit comments