mirror of
https://github.com/github/codeql.git
synced 2026-04-30 19:26:02 +02:00
JS: add ad hoc whitelist checks as sanitizers
This commit is contained in:
@@ -625,6 +625,28 @@ module TaintTracking {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* A check of the form `if(<isWhitelisted>(x))`, which sanitizes `x` in its "then" branch.
|
||||
*
|
||||
* `<isWhitelisted>` is a call with callee name 'safe', 'whitelist', 'allow', or similar.
|
||||
*/
|
||||
private class AdHocWhitelistCheckSanitizer extends AdditionalSanitizerGuardNode, DataFlow::CallNode {
|
||||
AdHocWhitelistCheckSanitizer() {
|
||||
getCalleeName().regexpMatch("(?i).*(safe|whitelist|allow|auth).*") and
|
||||
getNumArgument() = 1
|
||||
}
|
||||
|
||||
override predicate sanitizes(boolean outcome, Expr e) {
|
||||
outcome = true and
|
||||
e = getArgument(0).asExpr()
|
||||
}
|
||||
|
||||
override predicate appliesTo(Configuration cfg) {
|
||||
any()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** A check of the form `if(x in o)`, which sanitizes `x` in its "then" branch. */
|
||||
class InSanitizer extends AdditionalSanitizerGuardNode, DataFlow::ValueNode {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user