Skip to content

Commit 8e47a9b

Browse files
committed
add sanitizer step for .length in js/resource-exhaustion
1 parent a2d2626 commit 8e47a9b

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

javascript/ql/lib/semmle/javascript/security/dataflow/ResourceExhaustionQuery.qll

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ class Configuration extends TaintTracking::Configuration {
3737
guard instanceof LoopBoundInjection::LengthCheckSanitizerGuard or
3838
guard instanceof UpperBoundsCheckSanitizerGuard
3939
}
40+
41+
override predicate isSanitizerEdge(DataFlow::Node pred, DataFlow::Node succ) {
42+
succ.(DataFlow::PropRead).accesses(pred, "length")
43+
}
4044
}
4145

4246
predicate isRestrictedAdditionalTaintStep(DataFlow::Node src, DataFlow::Node dst) {
@@ -50,7 +54,7 @@ predicate isRestrictedAdditionalTaintStep(DataFlow::Node src, DataFlow::Node dst
5054
*/
5155
predicate isNumericFlowStep(DataFlow::Node src, DataFlow::Node dst) {
5256
// steps that introduce or preserve a number
53-
dst.(DataFlow::PropRead).accesses(src, ["length", "size"])
57+
dst.(DataFlow::PropRead).accesses(src, ["size"])
5458
or
5559
exists(DataFlow::CallNode c |
5660
c = dst and

javascript/ql/test/query-tests/Security/CWE-770/ResourceExhaustion/resource-exhaustion.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,6 @@ var server = http.createServer(function(req, res) {
8282
setTimeout(f, s); // NOT OK
8383
setInterval(f, n); // NOT OK
8484
setInterval(f, s); // NOT OK
85+
86+
Buffer.alloc(n.length); // OK - only allocing as much as the length of the input.
8587
});

0 commit comments

Comments
 (0)