mirror of
https://github.com/github/codeql.git
synced 2026-05-02 04:05:14 +02:00
add typeof sanitizer to js/shell-command-constructed-from-input
This commit is contained in:
@@ -189,4 +189,25 @@ module UnsafeShellCommandConstruction {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A check of the form `type x === "X"`, where x is "number", or "boolean",
|
||||
* which sanitized `x` in its "then" branch.
|
||||
*/
|
||||
class TypeOfSanitizer extends TaintTracking::SanitizerGuardNode, DataFlow::ValueNode {
|
||||
Expr x;
|
||||
override EqualityTest astNode;
|
||||
|
||||
TypeOfSanitizer() {
|
||||
exists(StringLiteral str, TypeofExpr typeof | astNode.hasOperands(str, typeof) |
|
||||
str.getValue() = ["number", "boolean"] and // "undefined" is already handled in TaintTracking.qll
|
||||
typeof.getOperand() = x
|
||||
)
|
||||
}
|
||||
|
||||
override predicate sanitizes(boolean outcome, Expr e) {
|
||||
outcome = astNode.getPolarity() and
|
||||
e = x
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -339,3 +339,9 @@ module.exports.unproblematic = function() {
|
||||
module.exports.problematic = function(n) {
|
||||
cp.exec("rm -rf " + id(n)); // NOT OK
|
||||
};
|
||||
|
||||
module.exports.typeofNumber = function(n) {
|
||||
if (typeof n === "number") {
|
||||
cp.exec("rm -rf " + n); // OK
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user