@@ -55,12 +55,8 @@ module UrlRedirect {
5555 abstract class Sanitizer extends DataFlow:: Node {
5656 /**
5757 * Holds if this sanitizer sanitizes flow in the given state.
58- *
59- * By default, sanitizers sanitize all flow, but some sanitiziers, for example,
60- * do not handle untrusted input that contains backslashes, so they only sanitize
61- * flow in the `NoBackslashes` state.
6258 */
63- predicate sanitizes ( FlowState state ) { any ( ) }
59+ abstract predicate sanitizes ( FlowState state ) ;
6460 }
6561
6662 /**
@@ -105,16 +101,23 @@ module UrlRedirect {
105101 string_concat .getRight ( ) = this .asCfgNode ( )
106102 )
107103 }
104+
105+ override predicate sanitizes ( FlowState state ) {
106+ // sanitize all flow states
107+ any ( )
108+ }
108109 }
109110
110111 /**
111- * A call to replace backslashes with forward slashes or eliminates them
112+ * A call that replaces backslashes with forward slashes or eliminates them
112113 * altogether, considered as a partial sanitizer, as well as an additional
113114 * flow step.
114115 */
115116 class ReplaceBackslashesSanitizer extends Sanitizer , AdditionalFlowStep , DataFlow:: MethodCallNode {
117+ DataFlow:: Node receiver ;
118+
116119 ReplaceBackslashesSanitizer ( ) {
117- this .getFunction ( ) . ( DataFlow :: AttrRead ) . getAttributeName ( ) = "replace" and
120+ this .calls ( receiver , "replace" ) and
118121 this .getArg ( 0 ) .asExpr ( ) .( StrConst ) .getText ( ) = "\\" and
119122 this .getArg ( 1 ) .asExpr ( ) .( StrConst ) .getText ( ) in [ "/" , "" ]
120123 }
@@ -124,7 +127,7 @@ module UrlRedirect {
124127 override predicate step (
125128 DataFlow:: Node nodeFrom , FlowState stateFrom , DataFlow:: Node nodeTo , FlowState stateTo
126129 ) {
127- nodeFrom = this . getObject ( ) and
130+ nodeFrom = receiver and
128131 stateFrom instanceof MayContainBackslashes and
129132 nodeTo = this and
130133 stateTo instanceof NoBackslashes
@@ -134,5 +137,10 @@ module UrlRedirect {
134137 /**
135138 * A comparison with a constant string, considered as a sanitizer-guard.
136139 */
137- class StringConstCompareAsSanitizerGuard extends Sanitizer , StringConstCompareBarrier { }
140+ class StringConstCompareAsSanitizerGuard extends Sanitizer , StringConstCompareBarrier {
141+ override predicate sanitizes ( FlowState state ) {
142+ // sanitize all flow states
143+ any ( )
144+ }
145+ }
138146}
0 commit comments