Skip to content

Commit 5e31f3a

Browse files
committed
JS: polish js/disabling-certificate-validation
1 parent 6d6f29e commit 5e31f3a

File tree

5 files changed

+82
-13
lines changed

5 files changed

+82
-13
lines changed

change-notes/1.25/analysis-javascript.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
| Unsafe expansion of self-closing HTML tag (`js/unsafe-html-expansion`) | security, external/cwe/cwe-079, external/cwe/cwe-116 | Highlights potential XSS vulnerabilities caused by unsafe expansion of self-closing HTML tags. |
3838
| Unsafe shell command constructed from library input (`js/shell-command-constructed-from-input`) | correctness, security, external/cwe/cwe-078, external/cwe/cwe-088 | Highlights potential command injections due to a shell command being constructed from library inputs. Results are shown on LGTM by default. |
3939
| Improper code sanitization (`js/bad-code-sanitization`) | security, external/cwe/cwe-094, external/cwe/cwe-079, external/cwe/cwe-116 | Highlights string concatenation where code is constructed without proper sanitization. Results are shown on LGTM by default. |
40+
| Disabling certificate validation (`js/disabling-certificate-validation`) | security, external/cwe-295 | Highligts locations where SSL certificate validation is disabled . Results are shown on LGTM by default. |
4041

4142
## Changes to existing queries
4243

javascript/config/suites/javascript/security

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
+ semmlecode-javascript-queries/Security/CWE-134/TaintedFormatString.ql: /Security/CWE/CWE-134
2525
+ semmlecode-javascript-queries/Security/CWE-201/PostMessageStar.ql: /Security/CWE/CWE-201
2626
+ semmlecode-javascript-queries/Security/CWE-209/StackTraceExposure.ql: /Security/CWE/CWE-209
27+
+ semmlecode-javascript-queries/Security/CWE-295/DisablingCertificateValidation.ql: /Security/CWE/CWE-295
2728
+ semmlecode-javascript-queries/Security/CWE-312/CleartextStorage.ql: /Security/CWE/CWE-312
2829
+ semmlecode-javascript-queries/Security/CWE-312/CleartextLogging.ql: /Security/CWE/CWE-312
2930
+ semmlecode-javascript-queries/Security/CWE-313/PasswordInConfigurationFile.ql: /Security/CWE/CWE-313

javascript/ql/src/Security/CWE-295/DisablingCertificateValidation.qhelp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,67 @@
55

66
<overview>
77

8+
<p>
9+
10+
Certificate validation is the standard authentication
11+
method of a secure TLS connection. Without it, there is no guarantee
12+
about who the other party of a TLS connection is.
13+
14+
</p>
15+
16+
<p>
17+
18+
When testing software that uses TLS connections, it may be useful to
19+
disable the certificate validation temporarily. But disabling it in
20+
production environments is strongly discouraged, unless an alternative
21+
method of authentication is used.
22+
23+
</p>
24+
825
</overview>
926

1027
<recommendation>
1128

29+
<p>
30+
31+
Do not disable certificate validation for TLS connections.
32+
33+
</p>
34+
1235
</recommendation>
1336

1437
<example>
1538

39+
<p>
40+
41+
The following example shows a HTTPS connection that
42+
transfers confidential information to a remote server. But the
43+
connection is not secure since the <code>rejectUnauthorized</code>
44+
option of the connection is set to <code>false</code>. As a
45+
consequence, anyone can impersonate the remote server, and receive the
46+
confidential information.
47+
48+
</p>
49+
50+
<sample src="examples/DisablingCertificateValidation.js"/>
51+
52+
<p>
53+
54+
To make the connection secure, the
55+
<code>rejectUnauthorized</code> option should have its default value,
56+
or be set explicitly to <code>true</code>.
57+
58+
</p>
59+
1660
</example>
1761

1862
<references>
1963

64+
<li>Wikipedia: <a href="https://en.wikipedia.org/wiki/Transport_Layer_Security">Transport Layer Security
65+
(TLS)</a></li>
66+
67+
<li>Node.js: <a href="https://nodejs.org/api/tls.html">TLS (SSL)</a></li>
68+
2069
</references>
2170

2271
</qhelp>

javascript/ql/src/Security/CWE-295/DisablingCertificateValidation.ql

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,11 @@
1111

1212
import javascript
1313

14-
from DataFlow::PropWrite disable
15-
where
16-
exists(DataFlow::SourceNode env |
17-
env = NodeJSLib::process().getAPropertyRead("env") and
18-
disable = env.getAPropertyWrite("NODE_TLS_REJECT_UNAUTHORIZED") and
19-
disable.getRhs().mayHaveStringValue("0")
20-
)
21-
or
22-
exists(DataFlow::ObjectLiteralNode options, DataFlow::InvokeNode invk |
23-
options.flowsTo(invk.getAnArgument()) and
24-
disable = options.getAPropertyWrite("rejectUnauthorized") and
25-
disable.getRhs().(AnalyzedNode).getTheBooleanValue() = false
26-
|
14+
/**
15+
* Gets an options object for a TLS connection.
16+
*/
17+
DataFlow::ObjectLiteralNode tlsOptions() {
18+
exists(DataFlow::InvokeNode invk | result.flowsTo(invk.getAnArgument()) |
2719
invk instanceof NodeJSLib::NodeJSClientRequest
2820
or
2921
invk = DataFlow::moduleMember("https", "Agent").getAnInstantiation()
@@ -37,4 +29,16 @@ where
3729
or
3830
invk = DataFlow::moduleMember("tls", ["connect", "createServer"]).getACall()
3931
)
32+
}
33+
34+
from DataFlow::PropWrite disable
35+
where
36+
exists(DataFlow::SourceNode env |
37+
env = NodeJSLib::process().getAPropertyRead("env") and
38+
disable = env.getAPropertyWrite("NODE_TLS_REJECT_UNAUTHORIZED") and
39+
disable.getRhs().mayHaveStringValue("0")
40+
)
41+
or
42+
disable = tlsOptions().getAPropertyWrite("rejectUnauthorized") and
43+
disable.getRhs().(AnalyzedNode).getTheBooleanValue() = false
4044
select disable, "Disabling certificate validation is strongly discouraged."
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
let https = require("https");
2+
3+
https.request(
4+
{
5+
hostname: "secure.my-online-bank.com",
6+
port: 443,
7+
method: "POST",
8+
path: "send-confidential-information",
9+
rejectUnauthorized: false // BAD
10+
},
11+
response => {
12+
// ... communicate with secure.my-online-bank.com
13+
}
14+
);

0 commit comments

Comments
 (0)