Skip to content

Commit 5ff7d20

Browse files
committed
add taint step through arrify
1 parent e64f29f commit 5ff7d20

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

javascript/change-notes/2021-07-15-array-libs.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ lgtm,codescanning
33
Affected packages are
44
[array-from](https://npmjs.com/package/array-from),
55
[array.prototype.find](https://npmjs.com/package/array.prototype.find),
6-
[array-find](https://npmjs.com/package/array-find)
6+
[array-find](https://npmjs.com/package/array-find),
7+
[arrify](https://npmjs.com/package/arrify),
8+
[array-ify](https://npmjs.com/package/array-ify)

javascript/ql/src/semmle/javascript/Arrays.qll

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,4 +342,15 @@ private module ArrayLibraries {
342342
result = DataFlow::moduleImport(["array.prototype.find", "array-find"]).getACall() and
343343
array = result.getArgument(0)
344344
}
345+
346+
/**
347+
* A taint step through the `arrify` library, or other libraries that (maybe) convert values into arrays.
348+
*/
349+
private class ArrayifyStep extends TaintTracking::SharedTaintStep {
350+
override predicate step(DataFlow::Node pred, DataFlow::Node succ) {
351+
exists(API::CallNode call | call = API::moduleImport(["arrify", "array-ify"]).getACall() |
352+
pred = call.getArgument(0) and succ = call
353+
)
354+
}
355+
}
345356
}

javascript/ql/test/library-tests/TaintTracking/BasicTaintTracking.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ typeInferenceMismatch
1212
| array-mutation.js:31:33:31:40 | source() | array-mutation.js:32:8:32:8 | h |
1313
| array-mutation.js:35:36:35:43 | source() | array-mutation.js:36:8:36:8 | i |
1414
| array-mutation.js:39:17:39:24 | source() | array-mutation.js:40:8:40:8 | j |
15+
| arrays.js:2:15:2:22 | source() | arrays.js:5:10:5:20 | arrify(foo) |
16+
| arrays.js:2:15:2:22 | source() | arrays.js:8:10:8:22 | arrayIfy(foo) |
1517
| booleanOps.js:2:11:2:18 | source() | booleanOps.js:4:8:4:8 | x |
1618
| booleanOps.js:2:11:2:18 | source() | booleanOps.js:13:10:13:10 | x |
1719
| booleanOps.js:2:11:2:18 | source() | booleanOps.js:19:10:19:10 | x |
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
function test() {
2+
var foo = source();
3+
4+
const arrify = require("arrify");
5+
sink(arrify(foo)); // NOT OK
6+
7+
const arrayIfy = require("array-ify");
8+
sink(arrayIfy(foo)); // NOT OK
9+
}

0 commit comments

Comments
 (0)