Skip to content

Commit cb3bd49

Browse files
committed
add taint step through the json2csv library
1 parent db4c8df commit cb3bd49

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
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 JSON utility libraries.
3+
Affected packages are
4+
[json2csv](https://npmjs.com/package/json2csv)

javascript/ql/src/semmle/javascript/JsonStringifiers.qll

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,22 @@ class JsonStringifyCall extends DataFlow::CallNode {
3434
*/
3535
DataFlow::SourceNode getOutput() { result = this }
3636
}
37+
38+
/**
39+
* A taint step through the [`json2csv`](https://www.npmjs.com/package/json2csv) library.
40+
*/
41+
class JSON2CSVTaintStep extends TaintTracking::SharedTaintStep {
42+
override predicate step(DataFlow::Node pred, DataFlow::Node succ) {
43+
exists(API::CallNode call |
44+
call =
45+
API::moduleImport("json2csv")
46+
.getMember("Parser")
47+
.getInstance()
48+
.getMember("parse")
49+
.getACall()
50+
|
51+
pred = call.getArgument(0) and
52+
succ = call
53+
)
54+
}
55+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ typeInferenceMismatch
9090
| json-stringify.js:2:16:2:23 | source() | json-stringify.js:16:8:16:38 | require ... source) |
9191
| json-stringify.js:2:16:2:23 | source() | json-stringify.js:17:8:17:39 | require ... source) |
9292
| json-stringify.js:2:16:2:23 | source() | json-stringify.js:18:8:18:40 | require ... source) |
93+
| json-stringify.js:2:16:2:23 | source() | json-stringify.js:21:8:21:46 | new jso ... source) |
9394
| json-stringify.js:3:15:3:22 | source() | json-stringify.js:8:8:8:31 | jsonStr ... (taint) |
9495
| nested-props.js:4:13:4:20 | source() | nested-props.js:5:10:5:14 | obj.x |
9596
| nested-props.js:9:18:9:25 | source() | nested-props.js:10:10:10:16 | obj.x.y |

javascript/ql/test/library-tests/TaintTracking/json-stringify.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,7 @@ function foo() {
1616
sink(require("util").inspect(source)); // NOT OK
1717
sink(require("pretty-format")(source)); // NOT OK
1818
sink(require("object-inspect")(source)); // NOT OK
19+
20+
const json2csv = require('json2csv');
21+
sink(new json2csv.Parser(opts).parse(source)); // NOT OK
1922
}

0 commit comments

Comments
 (0)