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
You can extend the required [Helmet security settings](https://helmetjs.github.io/) using [data extensions](https://codeql.github.com/docs/codeql-language-guides/customizing-library-models-for-javascript/) in a [CodeQL model pack](https://docs.github.com/en/code-security/codeql-cli/using-the-advanced-functionality-of-the-codeql-cli/creating-and-working-with-codeql-packs#creating-a-codeql-model-pack).
4
+
5
+
They are defaulted to just `frameguard` and `contentSecurityPolicy`, but you can add more using this method, to require them not to be set to `false` (which explicitly disables them) in the Helmet configuration.
6
+
7
+
For example, this YAML model can be used inside a CodeQL model pack to require `frameguard` and `contentSecurityPolicy`:
8
+
9
+
```yaml
10
+
extensions:
11
+
- addsTo:
12
+
pack: codeql/javascript-all
13
+
extensible: requiredHelmetSecuritySetting
14
+
data:
15
+
- ["frameguard"]
16
+
- ["contentSecurityPolicy"]
17
+
```
18
+
19
+
Note: Using `frameguard` and `contentSecurityPolicy` is an example: the query already enforces these, so it is not necessary to add it with your own data extension.
20
+
21
+
A suitable [model pack](https://docs.github.com/en/code-security/codeql-cli/using-the-advanced-functionality-of-the-codeql-cli/creating-and-working-with-codeql-packs#creating-a-codeql-model-pack) might be:
- [Customizing library models for javascript](https://codeql.github.com/docs/codeql-language-guides/customizing-library-models-for-javascript/)
36
+
- [Creating and working with CodeQL packs](https://docs.github.com/en/code-security/codeql-cli/using-the-advanced-functionality-of-the-codeql-cli/creating-and-working-with-codeql-packs#creating-a-codeql-model-pack)
<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
+
7
+
This query detects Helmet misconfigurations that can lead to security vulnerabilities, specifically:
8
+
</p>
9
+
10
+
<ul>
11
+
<li>Disabling frame protection</li>
12
+
<li>Disabling Content Security Policy</li>
13
+
</ul>
14
+
15
+
<p>
16
+
Content Security Policy (CSP) helps spot and prevent injection attacks such as Cross-Site Scripting (XSS).
17
+
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
+
</p>
20
+
21
+
<p>
22
+
Users of the query can extend the set of required Helmet features by adding additional checks for them, using CodeQL <ahref="https://codeql.github.com/docs/codeql-language-guides/customizing-library-models-for-javascript/">data extensions</a> in a <ahref="https://docs.github.com/en/code-security/codeql-cli/using-the-advanced-functionality-of-the-codeql-cli/creating-and-working-with-codeql-packs#creating-a-codeql-model-pack">CodeQL model pack</a>. See <code>CUSTOMIZING.md</code> in the query source for more information.
23
+
</p>
24
+
25
+
</overview>
26
+
<recommendation>
27
+
<p>
28
+
To help mitigate these vulnerabilities, ensure that the following Helmet functions are not disabled, and are configured appropriately to your application:
29
+
</p>
30
+
31
+
<ul>
32
+
<li><code>frameguard</code></li>
33
+
<li><code>contentSecurityPolicy</code></li>
34
+
</ul>
35
+
</recommendation>
36
+
<example>
37
+
<p>
38
+
The following code snippet demonstrates Helmet configured in an insecure manner:
39
+
</p>
40
+
41
+
<samplesrc="examples/helmet_insecure.js" />
42
+
43
+
<p>
44
+
In this example, the defaults are used, which enables frame protection and a default Content Security Policy.
45
+
</p>
46
+
47
+
<samplesrc="examples/helmet_default.js" />
48
+
49
+
<p>
50
+
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>:
* @name Insecure configuration of Helmet security middleware
3
+
* @description The Helmet middleware is used to set security-related HTTP headers in Express applications. This query finds instances where the middleware is configured with important security features disabled.
* Added a new query, `js/insecure-helmet-configuration`, to detect instances where Helmet middleware is configured with important security features disabled.
0 commit comments