mirror of
https://github.com/github/codeql.git
synced 2026-05-01 03:35:13 +02:00
Merge pull request #89 from esben-semmle/js/sharpen-type-confusion
JS: remove emptiness checks from the type confusion `x.length` sinks
This commit is contained in:
@@ -101,7 +101,22 @@ module TypeConfusionThroughParameterTampering {
|
||||
|
||||
LengthAccess() {
|
||||
exists (DataFlow::PropRead read |
|
||||
read.accesses(this, "length")
|
||||
read.accesses(this, "length") and
|
||||
// exclude truthiness checks on the length: an array/string confusion cannot control an emptiness check
|
||||
not (
|
||||
exists (ConditionGuardNode cond |
|
||||
read.asExpr() = cond.getTest()
|
||||
)
|
||||
or
|
||||
exists (Comparison cmp, Expr zero |
|
||||
zero.getIntValue() = 0 and
|
||||
cmp.hasOperands(read.asExpr(), zero)
|
||||
)
|
||||
or
|
||||
exists (LogNotExpr neg |
|
||||
neg.getOperand() = read.asExpr()
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -50,3 +50,22 @@ express().get('/some/path/:foo', function(req, res) {
|
||||
var foo = req.params.foo;
|
||||
foo.indexOf(); // OK
|
||||
});
|
||||
|
||||
express().get('/some/path/:foo', function(req, res) {
|
||||
if (req.query.path.length) {} // OK
|
||||
req.query.path.length == 0; // OK
|
||||
!req.query.path.length; // OK
|
||||
req.query.path.length > 0; // OK
|
||||
});
|
||||
|
||||
express().get('/some/path/:foo', function(req, res) {
|
||||
let p = req.query.path;
|
||||
|
||||
if (typeof p !== 'string') {
|
||||
return;
|
||||
}
|
||||
|
||||
while (p.length) { // OK
|
||||
p = p.substr(1);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user