Skip to content
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 @@ -67,11 +67,56 @@ predicate isNumericFlowStep(DataFlow::Node src, DataFlow::Node dst) {
c = dst and
src = c.getAnArgument()
|
c = DataFlow::globalVarRef("Math").getAMemberCall(_) or
c = DataFlow::globalVarRef("Math").getAMemberCall(_) and
not (
c = DataFlow::globalVarRef("Math").getAMemberCall("min") and
isConstantNumber(c.getAnArgument().asExpr())
)
Comment thread
hvitved marked this conversation as resolved.
Resolved
or
c = DataFlow::globalVarRef(["Number", "parseInt", "parseFloat"]).getACall()
)
}

/** Holds if `e` evaluates to a finite constant value. */
private predicate isConstantNumber(Expr e) {
e =
any(NumberLiteral literal |
exists(literal.getIntValue())
or
// Subtracting an infinite floating-point value from itself does not yield zero.
exists(float value | value = literal.getFloatValue() and value - value = 0.0)
)
or
e =
any(UnaryExpr sign |
isConstantNumber(sign.getOperand()) and
(sign instanceof NegExpr or sign instanceof PlusExpr)
)
or
isConstantNumber(e.stripParens())
or
exists(Variable v, VariableDeclarator decl |
v.isLocal() or decl.getDeclStmt() instanceof ConstDeclStmt
|
e = v.getAnAccess() and
decl.getBindingPattern() = unique(VarDecl varDecl | varDecl = v.getADeclaration()) and
not v.isParameter() and
Comment thread
hvitved marked this conversation as resolved.
Resolved
not v.isNamespaceExport() and
not v = any(EnhancedForLoop loop).getAnIterationVariable() and
not exists(EnhancedForLoop loop | loop.getIteratorExpr().stripParens() = v.getAnAccess()) and
forex(Expr assigned | assigned = v.getAnAssignedExpr() | isConstantNumber(assigned)) and
forall(VarAccess write |
write = v.getAnAccess() and
write.isLValue()
|
exists(AssignExpr assignment |
write = assignment.getTarget().stripParens() and
isConstantNumber(assignment.getRhs())
)
)
)
}

/**
* A sanitizer that blocks taint flow if the size of a number is limited.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
category: minorAnalysis
---
* The `js/resource-exhaustion` query no longer reports values bounded by a numeric constant using `Math.min`.
Loading
Loading