mirror of
https://github.com/github/codeql.git
synced 2026-05-02 04:05:14 +02:00
Merge pull request #1218 from esben-semmle/js/whitelist-typeconfusion-lt1-checks
Approved by asger-semmle
This commit is contained in:
@@ -83,15 +83,25 @@ module TypeConfusionThroughParameterTampering {
|
||||
LengthAccess() {
|
||||
exists(DataFlow::PropRead read |
|
||||
read.accesses(this, "length") and
|
||||
// exclude truthiness checks on the length: an array/string confusion cannot control an emptiness check
|
||||
// an array/string confusion cannot control an emptiness check
|
||||
not (
|
||||
// `if (x.length) {...}`
|
||||
exists(ConditionGuardNode cond | read.asExpr() = cond.getTest())
|
||||
or
|
||||
// `x.length == 0`, `x.length > 0`
|
||||
exists(Comparison cmp, Expr zero |
|
||||
zero.getIntValue() = 0 and
|
||||
cmp.hasOperands(read.asExpr(), zero)
|
||||
)
|
||||
or
|
||||
// `x.length < 1`
|
||||
exists(RelationalComparison cmp |
|
||||
cmp.getLesserOperand() = read.asExpr() and
|
||||
cmp.getGreaterOperand().getIntValue() = 1 and
|
||||
not cmp.isInclusive()
|
||||
)
|
||||
or
|
||||
// `!x.length`
|
||||
exists(LogNotExpr neg | neg.getOperand() = read.asExpr())
|
||||
)
|
||||
)
|
||||
|
||||
@@ -68,4 +68,6 @@ express().get('/some/path/:foo', function(req, res) {
|
||||
while (p.length) { // OK
|
||||
p = p.substr(1);
|
||||
}
|
||||
|
||||
p.length < 1; // OK
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user