Skip to content

Commit 154d017

Browse files
authored
Merge pull request #8438 from erik-krogh/apiDisable
JS: add some API-nodes to js/disabling-certificate-validation
2 parents 9f014be + 195ce9c commit 154d017

File tree

3 files changed

+32
-18
lines changed

3 files changed

+32
-18
lines changed

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

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,25 @@
1313

1414
import javascript
1515

16-
/**
17-
* Gets an options object for a TLS connection.
18-
*/
19-
DataFlow::ObjectLiteralNode tlsOptions() {
20-
exists(DataFlow::InvokeNode invk | result.flowsTo(invk.getAnArgument()) |
21-
invk instanceof ClientRequest
22-
or
23-
invk = DataFlow::moduleMember("https", "Agent").getAnInstantiation()
24-
or
25-
exists(DataFlow::NewNode new |
26-
new = DataFlow::moduleMember("tls", "TLSSocket").getAnInstantiation()
27-
|
28-
invk = new or
29-
invk = new.getAMethodCall("renegotiate")
30-
)
31-
or
32-
invk = DataFlow::moduleMember("tls", ["connect", "createServer"]).getACall()
16+
/** Gets options argument for a potential TLS connection */
17+
DataFlow::InvokeNode tlsInvocation() {
18+
result instanceof ClientRequest
19+
or
20+
result = DataFlow::moduleMember("https", "Agent").getAnInstantiation()
21+
or
22+
exists(DataFlow::NewNode new |
23+
new = DataFlow::moduleMember("tls", "TLSSocket").getAnInstantiation()
24+
|
25+
result = new or
26+
result = new.getAMethodCall("renegotiate")
3327
)
28+
or
29+
result = DataFlow::moduleMember("tls", ["connect", "createServer"]).getACall()
3430
}
3531

32+
/** Gets an options object for a TLS connection. */
33+
DataFlow::ObjectLiteralNode tlsOptions() { result.flowsTo(tlsInvocation().getAnArgument()) }
34+
3635
from DataFlow::PropWrite disable
3736
where
3837
exists(DataFlow::SourceNode env |
@@ -41,6 +40,13 @@ where
4140
disable.getRhs().mayHaveStringValue("0")
4241
)
4342
or
44-
disable = tlsOptions().getAPropertyWrite("rejectUnauthorized") and
43+
(
44+
disable = tlsOptions().getAPropertyWrite("rejectUnauthorized")
45+
or
46+
// the same thing, but with API-nodes if they happen to be available
47+
exists(API::Node tlsInvk | tlsInvk.getAnInvocation() = tlsInvocation() |
48+
disable.getRhs() = tlsInvk.getAParameter().getMember("rejectUnauthorized").getARhs()
49+
)
50+
) and
4551
disable.getRhs().(AnalyzedNode).getTheBooleanValue() = false
4652
select disable, "Disabling certificate validation is strongly discouraged."

javascript/ql/test/query-tests/Security/CWE-295/DisablingCertificateValidation.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
| tst.js:39:2:39:29 | rejectU ... ndirect | Disabling certificate validation is strongly discouraged. |
99
| tst.js:45:2:45:28 | rejectU ... !!false | Disabling certificate validation is strongly discouraged. |
1010
| tst.js:48:2:48:26 | rejectU ... : !true | Disabling certificate validation is strongly discouraged. |
11+
| tst.js:74:9:74:33 | rejectU ... : false | Disabling certificate validation is strongly discouraged. |

javascript/ql/test/query-tests/Security/CWE-295/tst.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,10 @@ new https.Agent({
6868
new https.Agent({
6969
rejectUnauthorized: typeof getOptions().rejectUnauthorized === 'boolean' ? getOptions().rejectUnauthorized : undefined // OK
7070
});
71+
72+
function getSomeunsafeOptions() {
73+
return {
74+
rejectUnauthorized: false // NOT OK
75+
}
76+
}
77+
new https.Agent(getSomeunsafeOptions());

0 commit comments

Comments
 (0)