@@ -643,12 +643,56 @@ module TaintTracking {
643643
644644 }
645645
646+ /**
647+ * A check of the form `if(whitelist.indexOf(x) >= 0)`, which sanitizes `x` in its "then" branch.
648+ *
649+ * Similar relational checks are also supported.
650+ */
651+ private class RelationalIndexOfSanitizer extends AdditionalSanitizerGuardNode , DataFlow:: ValueNode {
652+ MethodCallExpr indexOf ;
653+ override RelationalComparison astNode ;
654+ boolean polarity ;
655+
656+ RelationalIndexOfSanitizer ( ) {
657+ exists ( Expr lesser , Expr greater |
658+ astNode .getLesserOperand ( ) = lesser and
659+ astNode .getGreaterOperand ( ) = greater and
660+ indexOf .getMethodName ( ) = "indexOf" |
661+ polarity = true and
662+ greater = indexOf and
663+ (
664+ lesser .getIntValue ( ) >= 0
665+ or
666+ lesser .getIntValue ( ) = - 1 and not astNode .isInclusive ( )
667+ )
668+ or
669+ polarity = false and
670+ lesser = indexOf and
671+ (
672+ greater .getIntValue ( ) = - 1
673+ or
674+ greater .getIntValue ( ) = 0 and not astNode .isInclusive ( )
675+ )
676+ )
677+ }
678+
679+ override predicate sanitizes ( boolean outcome , Expr e ) {
680+ outcome = polarity and
681+ e = indexOf .getArgument ( 0 )
682+ }
683+
684+ override predicate appliesTo ( Configuration cfg ) {
685+ any ( )
686+ }
687+
688+ }
689+
646690 /**
647691 * A check of the form `if(~whitelist.indexOf(x))`, which sanitizes `x` in its "then" branch.
648692 *
649693 * This sanitizer is equivalent to `if(whitelist.indexOf(x) != -1)`, since `~n = 0` iff `n = -1`.
650694 */
651- class BitwiseIndexOfSanitizer extends AdditionalSanitizerGuardNode , DataFlow:: ValueNode {
695+ private class BitwiseIndexOfSanitizer extends AdditionalSanitizerGuardNode , DataFlow:: ValueNode {
652696 MethodCallExpr indexOf ;
653697 override BitNotExpr astNode ;
654698
0 commit comments