Skip to content

Commit 40aa970

Browse files
committed
add support for the strip-json-comments library
1 parent 23c3be6 commit 40aa970

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

javascript/change-notes/2021-06-24-json.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ lgtm,codescanning
99
[replicator](https://npmjs.com/package/replicator),
1010
[safe-stable-stringify](https://npmjs.com/package/safe-stable-stringify),
1111
[fclone](https://npmjs.com/package/fclone),
12-
[json-cycle](https://npmjs.com/package/json-cycle)
12+
[json-cycle](https://npmjs.com/package/json-cycle),
13+
[strip-json-comments](https://npmjs.com/package/strip-json-comments)

javascript/ql/src/semmle/javascript/JsonParsers.qll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,15 @@ private class JsonParserCallWithCallback extends JsonParserCall {
7878

7979
override DataFlow::SourceNode getOutput() { result = getCallback(1).getParameter(1) }
8080
}
81+
82+
/**
83+
* A taint step through the `strip-json-comments` library.
84+
*/
85+
private class StripJsonCommentsStep extends TaintTracking::SharedTaintStep {
86+
override predicate step(DataFlow::Node pred, DataFlow::Node succ) {
87+
exists(API::CallNode call | call = API::moduleImport("strip-json-comments").getACall() |
88+
pred = call.getArgument(0) and
89+
succ = call
90+
)
91+
}
92+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ typeInferenceMismatch
9797
| json-stringify.js:2:16:2:23 | source() | json-stringify.js:34:8:34:51 | replica ... ource)) |
9898
| json-stringify.js:2:16:2:23 | source() | json-stringify.js:36:8:36:47 | require ... source) |
9999
| json-stringify.js:2:16:2:23 | source() | json-stringify.js:39:8:39:37 | jc.stri ... ource)) |
100+
| json-stringify.js:2:16:2:23 | source() | json-stringify.js:42:8:42:51 | JSON.st ... urce))) |
100101
| json-stringify.js:3:15:3:22 | source() | json-stringify.js:8:8:8:31 | jsonStr ... (taint) |
101102
| nested-props.js:4:13:4:20 | source() | nested-props.js:5:10:5:14 | obj.x |
102103
| 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
@@ -37,4 +37,7 @@ function foo() {
3737

3838
const jc = require('json-cycle');
3939
sink(jc.stringify(jc.parse(source))); // NOT OK
40+
41+
const stripper = require("strip-json-comments");
42+
sink(JSON.stringify(JSON.parse(stripper(source)))); // NOT OK
4043
}

0 commit comments

Comments
 (0)