Skip to content

Commit a86f50e

Browse files
authored
Merge pull request github#6135 from erik-krogh/chokidar
Approved by esbena
2 parents b66f4cb + 6cf275b commit a86f50e

File tree

4 files changed

+40
-1
lines changed

4 files changed

+40
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
lgtm,codescanning
2+
* Support for `chokidar` has improved. The `js/tainted-path` query now recognizes calls to `chokidar.watch`,
3+
and the security queries recognize the filenames returned by the library.
4+
Affected packages are
5+
[chokidar](https://npmjs.com/package/chokidar)

javascript/ql/src/semmle/javascript/frameworks/Files.qll

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,3 +452,21 @@ private class LibraryAccess extends FileSystemAccess, DataFlow::InvokeNode {
452452

453453
override DataFlow::Node getAPathArgument() { result = getArgument(pathArgument) }
454454
}
455+
456+
/**
457+
* A call to the library [`chokidar`](https://www.npmjs.com/package/chokidar), where a call to `on` receives file names.
458+
*/
459+
class Chokidar extends FileNameProducer, FileSystemAccess, API::CallNode {
460+
Chokidar() { this = API::moduleImport("chokidar").getMember("watch").getACall() }
461+
462+
override DataFlow::Node getAPathArgument() { result = getArgument(0) }
463+
464+
override DataFlow::Node getAFileName() {
465+
exists(DataFlow::CallNode onCall, int pathIndex |
466+
onCall = getAChainedMethodCall("on") and
467+
if onCall.getArgument(0).mayHaveStringValue("all") then pathIndex = 1 else pathIndex = 0
468+
|
469+
result = onCall.getCallback(1).getParameter(pathIndex)
470+
)
471+
}
472+
}

javascript/ql/test/library-tests/frameworks/Concepts/tests.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ getPathArgument
3434
| tst-file-names.js:44:12:44:49 | globule ... o.js"]) | tst-file-names.js:44:39:44:48 | ["foo.js"] |
3535
| tst-file-names.js:46:12:46:51 | globule ... .js"]}) | tst-file-names.js:46:34:46:49 | ["a.js", "b.js"] |
3636
| tst-file-names.js:47:12:47:52 | globule ... b.js"]) | tst-file-names.js:47:28:47:51 | ["foo/a ... /b.js"] |
37+
| tst-file-names.js:55:1:55:19 | chokidar.watch('.') | tst-file-names.js:55:16:55:18 | '.' |
3738
getReadNode
3839
| file-access.js:25:1:25:59 | jsonfil ... bj) {}) | file-access.js:25:52:25:54 | obj |
3940
| file-access.js:26:1:26:39 | jsonfil ... .json') | file-access.js:26:1:26:39 | jsonfil ... .json') |
@@ -78,6 +79,9 @@ fileNameSource
7879
| tst-file-names.js:46:12:46:51 | globule ... .js"]}) |
7980
| tst-file-names.js:47:12:47:52 | globule ... b.js"]) |
8081
| tst-file-names.js:51:15:51:23 | await foo |
82+
| tst-file-names.js:56:22:56:25 | path |
83+
| tst-file-names.js:59:17:59:20 | path |
84+
| tst-file-names.js:62:16:62:19 | path |
8185
persistentReadAccess_getAWrite
8286
| persistence.js:3:5:3:33 | localSt ... prop1') | persistence.js:2:5:2:37 | localSt ... 1', v1) |
8387
| persistence.js:6:5:6:35 | session ... prop2') | persistence.js:5:5:5:39 | session ... 2', v2) |

javascript/ql/test/library-tests/frameworks/Concepts/tst-file-names.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,16 @@ var map3 = globule.mapping(["foo/a.js", "foo/b.js"])
4949
async function bar() {
5050
var foo = globby(_);
5151
var files = await foo;
52-
}
52+
}
53+
54+
const chokidar = require('chokidar');
55+
chokidar.watch('.')
56+
.on('all', (event, path) => {
57+
console.log(event, path);
58+
})
59+
.on('change', path => {
60+
console.log(path);
61+
})
62+
.on('ready', path => {
63+
console.log(path);
64+
});

0 commit comments

Comments
 (0)