Skip to content

Commit f1a7f0a

Browse files
committed
V1
1 parent 38892bb commit f1a7f0a

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

javascript/ql/lib/semmle/javascript/frameworks/ShellJS.qll

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
11
/**
22
* Models the `shelljs` library in terms of `FileSystemAccess` and `SystemCommandExecution`.
3+
*
4+
* https://www.npmjs.com/package/shelljs
35
*/
46

57
import javascript
68

79
module ShellJS {
10+
API::Node shellJSMember() {
11+
result = API::moduleImport("shelljs")
12+
or
13+
result =
14+
shellJSMember()
15+
.getMember([
16+
"exec", "cd", "cp", "touch", "chmod", "pushd", "find", "ls", "ln", "mkdir", "mv",
17+
"rm", "cat", "head", "sort", "tail", "uniq", "grep", "sed", "to", "toEnd", "echo"
18+
])
19+
.getReturn()
20+
}
21+
822
/**
923
* Gets an import of the `shelljs` or `async-shelljs` module.
1024
*/
1125
DataFlow::SourceNode shelljs() {
12-
result = DataFlow::moduleImport("shelljs") or
26+
result = shellJSMember().asSource() or
1327
result = DataFlow::moduleImport("async-shelljs")
1428
}
1529

@@ -39,7 +53,10 @@ module ShellJS {
3953

4054
/** The `shelljs.exec` library modeled as a `shelljs` member. */
4155
private class ShellJsExec extends Range {
42-
ShellJsExec() { this = DataFlow::moduleImport("shelljs.exec") }
56+
ShellJsExec() {
57+
this = DataFlow::moduleImport("shelljs.exec") or
58+
this = shellJSMember().getMember("exec").asSource()
59+
}
4360

4461
override string getName() { result = "exec" }
4562
}

javascript/ql/test/library-tests/frameworks/Shelljs/ShellJS.expected

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,14 @@ test_FileSystemAccess
5252
| tst.js:56:1:56:18 | shelljs.uniq(file) |
5353
| tst.js:57:1:57:26 | shelljs ... file2) |
5454
| tst.js:58:1:58:32 | shelljs ... file2) |
55+
| tst.js:60:1:60:17 | shelljs.cat(file) |
56+
| tst.js:60:1:60:41 | shelljs ... cement) |
57+
| tst.js:61:1:61:17 | shelljs.cat(file) |
5558
test_MissingFileSystemAccess
5659
test_SystemCommandExecution
5760
| tst.js:14:1:14:27 | shelljs ... ts, cb) |
61+
| tst.js:60:1:60:51 | shelljs ... ec(cmd) |
62+
| tst.js:61:1:61:27 | shelljs ... ec(cmd) |
5863
test_FileNameSource
5964
| tst.js:15:1:15:26 | shelljs ... file2) |
6065
| tst.js:24:1:24:16 | shelljs.ls(file) |

javascript/ql/test/library-tests/frameworks/Shelljs/tst.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,6 @@ shelljs.touch(file1, file2);
5656
shelljs.uniq(file);
5757
shelljs.uniq(file1, file2);
5858
shelljs.uniq(opts, file1, file2);
59+
60+
shelljs.cat(file).sed(regex, replacement).exec(cmd);
61+
shelljs.cat(file).exec(cmd);

0 commit comments

Comments
 (0)