@@ -587,14 +587,14 @@ module TaintTracking {
587587
588588 }
589589
590- /** A check of the form `if(o .indexOf(x) != -1)`, which sanitizes `x` in its "then" branch. */
590+ /** A check of the form `if(whitelist .indexOf(x) != -1)`, which sanitizes `x` in its "then" branch. */
591591 class IndexOfSanitizer extends AdditionalSanitizerGuardNode , DataFlow:: ValueNode {
592592 MethodCallExpr indexOf ;
593593 override EqualityTest astNode ;
594594
595595 IndexOfSanitizer ( ) {
596596 exists ( Expr index | astNode .hasOperands ( indexOf , index ) |
597- // one operand is of the form `o .indexOf(x)`
597+ // one operand is of the form `whitelist .indexOf(x)`
598598 indexOf .getMethodName ( ) = "indexOf" and
599599 // and the other one is -1
600600 index .getIntValue ( ) = - 1
@@ -612,6 +612,30 @@ module TaintTracking {
612612
613613 }
614614
615+ /**
616+ * A check of the form `if(~whitelist.indexOf(x))`, which sanitizes `x` in its "then" branch.
617+ *
618+ * This sanitizer is equivalent to `if(whitelist.indexOf(x) != -1)`, since `~n = 0` iff `n = -1`.
619+ */
620+ class BitwiseIndexOfSanitizer extends AdditionalSanitizerGuardNode , DataFlow:: ValueNode {
621+ MethodCallExpr indexOf ;
622+ override BitNotExpr astNode ;
623+
624+ BitwiseIndexOfSanitizer ( ) {
625+ astNode .getOperand ( ) = indexOf and
626+ indexOf .getMethodName ( ) = "indexOf"
627+ }
628+
629+ override predicate sanitizes ( boolean outcome , Expr e ) {
630+ outcome = true and
631+ e = indexOf .getArgument ( 0 )
632+ }
633+
634+ override predicate appliesTo ( Configuration cfg ) {
635+ any ( )
636+ }
637+
638+ }
615639
616640 /** A check of the form `if(x == 'some-constant')`, which sanitizes `x` in its "then" branch. */
617641 class ConstantComparison extends AdditionalSanitizerGuardNode , DataFlow:: ValueNode {
0 commit comments