Skip to content

Commit f6f63e2

Browse files
committed
add model for the array-from polyfill
1 parent d34e748 commit f6f63e2

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
lgtm,codescanning
2+
* The dataflow libraries now model dataflow through more array libraries.
3+
Affected packages are
4+
[array-from](https://npmjs.com/package/array-from)

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ module ArrayTaintTracking {
6868
succ = call
6969
or
7070
// `e = Array.from(x)`: if `x` is tainted, then so is `e`.
71-
call = DataFlow::globalVarRef("Array").getAPropertyRead("from").getACall() and
71+
call = arrayFromCall() and
7272
pred = call.getAnArgument() and
7373
succ = call
7474
or
@@ -97,7 +97,7 @@ private module ArrayDataFlow {
9797
DataFlow::Node pred, DataFlow::Node succ, string fromProp, string toProp
9898
) {
9999
exists(DataFlow::CallNode call |
100-
call = DataFlow::globalVarRef("Array").getAMemberCall("from") and
100+
call = arrayFromCall() and
101101
pred = call.getArgument(0) and
102102
succ = call and
103103
fromProp = arrayLikeElement() and
@@ -298,3 +298,19 @@ private module ArrayDataFlow {
298298
}
299299
}
300300
}
301+
302+
private import ArrayLibraries
303+
304+
/**
305+
* Classes and predicates modelling various libraries that work on arrays or array-like structures.
306+
*/
307+
private module ArrayLibraries {
308+
/**
309+
* Gets a call to `Array.from` or a polyfill implementing the same functionality.
310+
*/
311+
DataFlow::CallNode arrayFromCall() {
312+
result = DataFlow::globalVarRef("Array").getAMemberCall("from")
313+
or
314+
result = DataFlow::moduleImport("array-from").getACall()
315+
}
316+
}

javascript/ql/test/library-tests/Arrays/DataFlow.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
| arrays.js:2:16:2:23 | "source" | arrays.js:56:10:56:10 | x |
88
| arrays.js:2:16:2:23 | "source" | arrays.js:60:10:60:10 | x |
99
| arrays.js:2:16:2:23 | "source" | arrays.js:66:10:66:10 | x |
10+
| arrays.js:2:16:2:23 | "source" | arrays.js:71:10:71:10 | x |
1011
| arrays.js:18:22:18:29 | "source" | arrays.js:18:50:18:50 | e |
1112
| arrays.js:22:15:22:22 | "source" | arrays.js:23:8:23:17 | arr2.pop() |
1213
| arrays.js:25:15:25:22 | "source" | arrays.js:26:8:26:17 | arr3.pop() |

javascript/ql/test/library-tests/Arrays/arrays.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,9 @@
6565
for (const x of arr7) {
6666
sink(x); // NOT OK
6767
}
68+
69+
const arrayFrom = require("array-from");
70+
for (const x of arrayFrom(arr)) {
71+
sink(x); // NOT OK
72+
}
6873
});

0 commit comments

Comments
 (0)