Skip to content

Commit 2edeb4a

Browse files
authored
Merge pull request github#3735 from esbena/js/insecure-http-options
JS: polish js/disabling-certificate-validation
2 parents 69b44de + ca06f6d commit 2edeb4a

File tree

4 files changed

+81
-13
lines changed

4 files changed

+81
-13
lines changed

change-notes/1.25/analysis-javascript.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
| Creating biased random numbers from a cryptographically secure source (`js/biased-cryptographic-random`) | security, external/cwe/cwe-327 | Highlights mathematical operations on cryptographically secure numbers that can create biased results. Results are shown on LGTM by default. |
4242
| Storage of sensitive information in build artifact (`js/build-artifact-leak`) | security, external/cwe/cwe-312 | Highlights storage of sensitive information in build artifacts. Results are shown on LGTM by default. |
4343
| 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. |
44+
| Disabling certificate validation (`js/disabling-certificate-validation`) | security, external/cwe-295 | Highlights locations where SSL certificate validation is disabled. Results are shown on LGTM by default. |
4445
| Incomplete multi-character sanitization (`js/incomplete-multi-character-sanitization`) | correctness, security, external/cwe/cwe-20, external/cwe/cwe-116 | Highlights sanitizers that fail to remove dangerous substrings completely. Results are shown on LGTM by default. |
4546

4647
## Changes to existing queries

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 method of a
11+
secure TLS connection. Without it, there is no guarantee about who the other party of a TLS connection is, making man-in-the-middle attacks more likely to occur
12+
13+
</p>
14+
15+
<p>
16+
17+
When testing software that uses TLS connections, it may be useful to
18+
disable the certificate validation temporarily. But disabling it in
19+
production environments is strongly discouraged, unless an alternative
20+
method of authentication is used.
21+
22+
</p>
23+
824
</overview>
925

1026
<recommendation>
1127

28+
<p>
29+
30+
Do not disable certificate validation for TLS connections.
31+
32+
</p>
33+
1234
</recommendation>
1335

1436
<example>
1537

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

1861
<references>
1962

63+
<li>Wikipedia: <a href="https://en.wikipedia.org/wiki/Transport_Layer_Security">Transport Layer Security (TLS)</a></li>
64+
65+
<li>Wikipedia: <a href="https://en.wikipedia.org/wiki/Man-in-the-middle_attack">Man-in-the-middle attack</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)