Skip to content

Commit f5d465f

Browse files
committed
Added data extension to allow setting extra required Helmet features
1 parent 68e21a5 commit f5d465f

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

javascript/ql/src/Security/CWE-693/InsecureHelmet.qhelp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<qhelp>
33
<overview>
44
<p>
5-
<a href="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.
5+
<a href="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.<br>
66

77
This query detects Helmet misconfigurations that can lead to security vulnerabilities, specifically:
88
</p>
@@ -13,10 +13,28 @@
1313
</ul>
1414

1515
<p>
16-
Content Security Policy (CSP) helps spot and prevent injection attacks such as Cross-Site Scripting (XSS).
16+
Content Security Policy (CSP) helps spot and prevent injection attacks such as Cross-Site Scripting (XSS).<br>
1717

1818
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.
1919
</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 <a href="https://codeql.github.com/docs/codeql-language-guides/customizing-library-models-for-javascript/">data extensions</a>.
23+
</p>
24+
25+
<pre>
26+
extensions:
27+
- addsTo:
28+
pack: codeql/javascript-all
29+
extensible: requiredHelmetSecuritySetting
30+
data:
31+
- name: "frameguard"
32+
</pre>
33+
34+
<p>
35+
Note: <code>frameguard</code> is an example: the query already enforces this setting, so it is not necessary to add it to the data extension.
36+
</p>
37+
2038
</overview>
2139
<recommendation>
2240
<p>

javascript/ql/src/Security/CWE-693/InsecureHelmet.ql

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,27 @@ class HelmetProperty extends Property {
2727
predicate isImportantSecuritySetting() {
2828
this.getName() in ["frameguard", "contentSecurityPolicy"]
2929
// read from data extensions to allow enforcing other settings
30-
// TODO
30+
or requiredHelmetSecuritySetting(this.getName())
3131
}
3232
}
3333

34+
/*
35+
* Extend the required Helmet security settings using data extensions.
36+
* Docs: https://codeql.github.com/docs/codeql-language-guides/customizing-library-models-for-javascript/
37+
* For example:
38+
39+
extensions:
40+
- addsTo:
41+
pack: codeql/javascript-all
42+
extensible: requiredHelmetSecuritySetting
43+
data:
44+
- name: "frameguard"
45+
46+
* Note: `frameguard` is an example: the query already enforces this setting, so it is not necessary to add it to the data extension.
47+
48+
*/
49+
extensible predicate requiredHelmetSecuritySetting(string name);
50+
3451
from HelmetProperty helmetSetting, ExpressLibraries::HelmetRouteHandler helmet
3552
where
3653
helmetSetting.isFalse() and

0 commit comments

Comments
 (0)