Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS: sanitize taint in the LHS of && #4681

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ module TaintTracking {

/** Holds if the edge from `pred` to `succ` is a taint sanitizer for data labelled with `lbl`. */
predicate isSanitizerEdge(DataFlow::Node pred, DataFlow::Node succ, DataFlow::FlowLabel lbl) {
none()
// sanitize the falsy LHS of `LHS && RHS` by default
pred.asExpr() = any(LogAndExpr e).getLeftOperand() and lbl.isTaint()
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,5 @@ typeInferenceMismatch
| tst.js:2:13:2:20 | source() | tst.js:45:10:45:24 | x.map(x2 => x2) |
| tst.js:2:13:2:20 | source() | tst.js:47:10:47:30 | Buffer. ... 'hex') |
| tst.js:2:13:2:20 | source() | tst.js:48:10:48:22 | new Buffer(x) |
| tst.js:2:13:2:20 | source() | tst.js:51:7:51:12 | x && x |
| tst.js:2:13:2:20 | source() | tst.js:52:7:52:12 | y && x |
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,6 @@
| thisAssignments.js:4:17:4:24 | source() | thisAssignments.js:5:10:5:18 | obj.field |
| thisAssignments.js:7:19:7:26 | source() | thisAssignments.js:8:10:8:20 | this.field2 |
| tst.js:2:13:2:20 | source() | tst.js:4:10:4:10 | x |
| tst.js:2:13:2:20 | source() | tst.js:50:7:50:12 | x && y |
| tst.js:2:13:2:20 | source() | tst.js:51:7:51:12 | x && x |
| tst.js:2:13:2:20 | source() | tst.js:52:7:52:12 | y && x |
4 changes: 4 additions & 0 deletions javascript/ql/test/library-tests/TaintTracking/tst.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,8 @@ function test() {

sink(Buffer.from(x, 'hex')); // NOT OK
sink(new Buffer(x)); // NOT OK

sink(x && y); // OK
sink(x && x); // NOT OK
sink(y && x); // NOT OK
}