JS: address review comments: improve regex, limit sanitizer usage

This commit is contained in:
Esben Sparre Andreasen
2018-09-26 09:20:07 +02:00
parent 42fc28bc55
commit 52061b35d8
3 changed files with 14 additions and 6 deletions

View File

@@ -629,10 +629,12 @@ 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.
*
* This sanitizer is not enabled by default.
*/
private class AdHocWhitelistCheckSanitizer extends AdditionalSanitizerGuardNode, DataFlow::CallNode {
class AdHocWhitelistCheckSanitizer extends SanitizerGuardNode, DataFlow::CallNode {
AdHocWhitelistCheckSanitizer() {
getCalleeName().regexpMatch("(?i).*(safe|whitelist|allow|auth).*") and
getCalleeName().regexpMatch("(?i).*((?<!un)safe|whitelist|allow|(?<!un)auth(?!or\\b)).*") and
getNumArgument() = 1
}
@@ -641,10 +643,6 @@ module TaintTracking {
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. */

View File

@@ -49,6 +49,11 @@ module CorsMisconfigurationForCredentials {
super.isSanitizer(node) or
node instanceof Sanitizer
}
override predicate isSanitizerGuard(TaintTracking::SanitizerGuardNode guard) {
guard instanceof TaintTracking::AdHocWhitelistCheckSanitizer
}
}
/** A source of remote user input, considered as a flow source for CORS misconfiguration. */

View File

@@ -23,4 +23,9 @@ class ExampleConfiguration extends TaintTracking::Configuration {
)
}
override predicate isSanitizerGuard(TaintTracking::SanitizerGuardNode guard) {
// add additional generic sanitizers
guard instanceof TaintTracking::AdHocWhitelistCheckSanitizer
}
}