Skip to content

Commit 94a5722

Browse files
author
Max Schaefer
committed
JavaScript: Model taint propagation through new Buffer and Buffer.from.
1 parent 4091cf4 commit 94a5722

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

javascript/ql/src/semmle/javascript/frameworks/NodeJSLib.qll

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,22 @@ module NodeJSLib {
297297
override predicate step(DataFlow::Node pred, DataFlow::Node succ) {
298298
pred = tainted and succ = this
299299
}
300+
}
301+
302+
/**
303+
* A model of taint propagation through `new Buffer` and `Buffer.from`.
304+
*/
305+
private class BufferTaintStep extends TaintTracking::AdditionalTaintStep, DataFlow::InvokeNode {
306+
BufferTaintStep() {
307+
this = DataFlow::globalVarRef("Buffer").getAnInstantiation()
308+
or
309+
this = DataFlow::globalVarRef("Buffer").getAMemberInvocation("from")
310+
}
300311

312+
override predicate step(DataFlow::Node pred, DataFlow::Node succ) {
313+
pred = getArgument(0) and
314+
succ = this
315+
}
301316
}
302317

303318
/**

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,5 @@
2323
| tst.js:2:13:2:20 | source() | tst.js:41:14:41:16 | ary |
2424
| tst.js:2:13:2:20 | source() | tst.js:44:10:44:30 | innocen ... ) => x) |
2525
| tst.js:2:13:2:20 | source() | tst.js:45:10:45:24 | x.map(x2 => x2) |
26+
| tst.js:2:13:2:20 | source() | tst.js:47:10:47:30 | Buffer. ... 'hex') |
27+
| tst.js:2:13:2:20 | source() | tst.js:48:10:48:22 | new Buffer(x) |

javascript/ql/test/library-tests/TaintTracking/tst.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,6 @@ function test() {
4444
sink(innocent.map(() => x)); // NOT OK
4545
sink(x.map(x2 => x2)); // NOT OK
4646

47+
sink(Buffer.from(x, 'hex')); // NOT OK
48+
sink(new Buffer(x)); // NOT OK
4749
}

0 commit comments

Comments
 (0)