Skip to content

Commit d4b5ef6

Browse files
committed
Refactor process.env handling in CleartextLogging and IndirectCommandInjection modules to use ThreatModelSource
1 parent 33d8ffa commit d4b5ef6

File tree

5 files changed

+19
-7
lines changed

5 files changed

+19
-7
lines changed

javascript/ql/lib/semmle/javascript/security/dataflow/CleartextLoggingCustomizations.qll

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ module CleartextLogging {
171171

172172
/** An access to the sensitive object `process.env`. */
173173
class ProcessEnvSource extends Source {
174-
ProcessEnvSource() { this = NodeJSLib::process().getAPropertyRead("env") }
174+
ProcessEnvSource() { this.(ThreatModelSource).getThreatModel() = "environment" }
175175

176176
override string describe() { result = "process environment" }
177177
}

javascript/ql/lib/semmle/javascript/security/dataflow/IndirectCommandInjectionCustomizations.qll

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ module IndirectCommandInjection {
2929
* A read of `process.env`, considered as a flow source for command injection.
3030
*/
3131
private class ProcessEnvAsSource extends Source {
32-
ProcessEnvAsSource() { this = NodeJSLib::process().getAPropertyRead("env") }
32+
ProcessEnvAsSource() { this.(ThreatModelSource).getThreatModel() = "environment" }
3333

3434
override string describe() { result = "environment variable" }
3535
}
3636

3737
/** Gets a data flow node referring to `process.env`. */
3838
private DataFlow::SourceNode envObject(DataFlow::TypeTracker t) {
3939
t.start() and
40-
result = NodeJSLib::process().getAPropertyRead("env")
40+
result.(ThreatModelSource).getThreatModel() = "environment"
4141
or
4242
exists(DataFlow::TypeTracker t2 | result = envObject(t2).track(t2, t))
4343
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ DataFlow::ObjectLiteralNode tlsOptions() { result.flowsTo(tlsInvocation().getAnA
3737
from DataFlow::PropWrite disable
3838
where
3939
exists(DataFlow::SourceNode env |
40-
env = NodeJSLib::process().getAPropertyRead("env") and
40+
env.(ThreatModelSource).getThreatModel() = "environment" and
4141
disable = env.getAPropertyWrite("NODE_TLS_REJECT_UNAUTHORIZED") and
4242
disable.getRhs().mayHaveStringValue("0")
4343
)

javascript/ql/test/query-tests/Security/CWE-078/IndirectCommandInjection/IndirectCommandInjection.expected

+12
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
| actions.js:4:6:4:29 | process ... _DATA'] | actions.js:4:6:4:16 | process.env | actions.js:4:6:4:29 | process ... _DATA'] | This command depends on an unsanitized $@. | actions.js:4:6:4:16 | process.env | environment variable |
33
| actions.js:8:10:8:23 | e['TEST_DATA'] | actions.js:12:6:12:16 | process.env | actions.js:8:10:8:23 | e['TEST_DATA'] | This command depends on an unsanitized $@. | actions.js:12:6:12:16 | process.env | environment variable |
44
| actions.js:14:6:14:21 | getInput('data') | actions.js:14:6:14:21 | getInput('data') | actions.js:14:6:14:21 | getInput('data') | This command depends on an unsanitized $@. | actions.js:14:6:14:21 | getInput('data') | GitHub Actions user input |
5+
| actions.js:18:10:18:40 | 'rm -rf ... 'SOME'] | actions.js:18:22:18:32 | shelljs.env | actions.js:18:10:18:40 | 'rm -rf ... 'SOME'] | This command depends on an unsanitized $@. | actions.js:18:22:18:32 | shelljs.env | environment variable |
6+
| actions.js:19:10:19:37 | 'rm -rf ... nv.SOME | actions.js:19:22:19:32 | shelljs.env | actions.js:19:10:19:37 | 'rm -rf ... nv.SOME | This command depends on an unsanitized $@. | actions.js:19:22:19:32 | shelljs.env | environment variable |
7+
| actions.js:20:10:20:32 | 'rm -rf ... ljs.env | actions.js:20:22:20:32 | shelljs.env | actions.js:20:10:20:32 | 'rm -rf ... ljs.env | This command depends on an unsanitized $@. | actions.js:20:22:20:32 | shelljs.env | environment variable |
58
| command-line-parameter-command-injection.js:4:10:4:21 | process.argv | command-line-parameter-command-injection.js:4:10:4:21 | process.argv | command-line-parameter-command-injection.js:4:10:4:21 | process.argv | This command depends on an unsanitized $@. | command-line-parameter-command-injection.js:4:10:4:21 | process.argv | command-line argument |
69
| command-line-parameter-command-injection.js:8:10:8:36 | "cmd.sh ... argv[2] | command-line-parameter-command-injection.js:8:22:8:33 | process.argv | command-line-parameter-command-injection.js:8:10:8:36 | "cmd.sh ... argv[2] | This command depends on an unsanitized $@. | command-line-parameter-command-injection.js:8:22:8:33 | process.argv | command-line argument |
710
| command-line-parameter-command-injection.js:11:14:11:20 | args[0] | command-line-parameter-command-injection.js:10:13:10:24 | process.argv | command-line-parameter-command-injection.js:11:14:11:20 | args[0] | This command depends on an unsanitized $@. | command-line-parameter-command-injection.js:10:13:10:24 | process.argv | command-line argument |
@@ -44,6 +47,9 @@ edges
4447
| actions.js:7:15:7:15 | e | actions.js:8:10:8:10 | e | provenance | |
4548
| actions.js:8:10:8:10 | e | actions.js:8:10:8:23 | e['TEST_DATA'] | provenance | |
4649
| actions.js:12:6:12:16 | process.env | actions.js:7:15:7:15 | e | provenance | |
50+
| actions.js:18:22:18:32 | shelljs.env | actions.js:18:10:18:40 | 'rm -rf ... 'SOME'] | provenance | |
51+
| actions.js:19:22:19:32 | shelljs.env | actions.js:19:10:19:37 | 'rm -rf ... nv.SOME | provenance | |
52+
| actions.js:20:22:20:32 | shelljs.env | actions.js:20:10:20:32 | 'rm -rf ... ljs.env | provenance | |
4753
| command-line-parameter-command-injection.js:8:22:8:33 | process.argv | command-line-parameter-command-injection.js:8:10:8:36 | "cmd.sh ... argv[2] | provenance | |
4854
| command-line-parameter-command-injection.js:10:6:10:33 | args | command-line-parameter-command-injection.js:11:14:11:17 | args | provenance | |
4955
| command-line-parameter-command-injection.js:10:6:10:33 | args | command-line-parameter-command-injection.js:12:26:12:29 | args | provenance | |
@@ -181,6 +187,12 @@ nodes
181187
| actions.js:8:10:8:23 | e['TEST_DATA'] | semmle.label | e['TEST_DATA'] |
182188
| actions.js:12:6:12:16 | process.env | semmle.label | process.env |
183189
| actions.js:14:6:14:21 | getInput('data') | semmle.label | getInput('data') |
190+
| actions.js:18:10:18:40 | 'rm -rf ... 'SOME'] | semmle.label | 'rm -rf ... 'SOME'] |
191+
| actions.js:18:22:18:32 | shelljs.env | semmle.label | shelljs.env |
192+
| actions.js:19:10:19:37 | 'rm -rf ... nv.SOME | semmle.label | 'rm -rf ... nv.SOME |
193+
| actions.js:19:22:19:32 | shelljs.env | semmle.label | shelljs.env |
194+
| actions.js:20:10:20:32 | 'rm -rf ... ljs.env | semmle.label | 'rm -rf ... ljs.env |
195+
| actions.js:20:22:20:32 | shelljs.env | semmle.label | shelljs.env |
184196
| command-line-parameter-command-injection.js:4:10:4:21 | process.argv | semmle.label | process.argv |
185197
| command-line-parameter-command-injection.js:8:10:8:36 | "cmd.sh ... argv[2] | semmle.label | "cmd.sh ... argv[2] |
186198
| command-line-parameter-command-injection.js:8:22:8:33 | process.argv | semmle.label | process.argv |

javascript/ql/test/query-tests/Security/CWE-078/IndirectCommandInjection/actions.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ exec(getInput('data')); // $ Alert
1515

1616
function test2(e) {
1717
const shelljs = require('shelljs');
18-
exec('rm -rf ' + shelljs.env['SOME']); // $ MISSING: Alert
19-
exec('rm -rf ' + shelljs.env.SOME); // $ MISSING: Alert
20-
exec('rm -rf ' + shelljs.env); // $ MISSING: Alert
18+
exec('rm -rf ' + shelljs.env['SOME']); // $ Alert
19+
exec('rm -rf ' + shelljs.env.SOME); // $ Alert
20+
exec('rm -rf ' + shelljs.env); // $ Alert
2121
}

0 commit comments

Comments
 (0)