@@ -55,12 +55,8 @@ module UrlRedirect {
55
55
abstract class Sanitizer extends DataFlow:: Node {
56
56
/**
57
57
* 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.
62
58
*/
63
- predicate sanitizes ( FlowState state ) { any ( ) }
59
+ abstract predicate sanitizes ( FlowState state ) ;
64
60
}
65
61
66
62
/**
@@ -105,16 +101,23 @@ module UrlRedirect {
105
101
string_concat .getRight ( ) = this .asCfgNode ( )
106
102
)
107
103
}
104
+
105
+ override predicate sanitizes ( FlowState state ) {
106
+ // sanitize all flow states
107
+ any ( )
108
+ }
108
109
}
109
110
110
111
/**
111
- * A call to replace backslashes with forward slashes or eliminates them
112
+ * A call that replaces backslashes with forward slashes or eliminates them
112
113
* altogether, considered as a partial sanitizer, as well as an additional
113
114
* flow step.
114
115
*/
115
116
class ReplaceBackslashesSanitizer extends Sanitizer , AdditionalFlowStep , DataFlow:: MethodCallNode {
117
+ DataFlow:: Node receiver ;
118
+
116
119
ReplaceBackslashesSanitizer ( ) {
117
- this .getFunction ( ) . ( DataFlow :: AttrRead ) . getAttributeName ( ) = "replace" and
120
+ this .calls ( receiver , "replace" ) and
118
121
this .getArg ( 0 ) .asExpr ( ) .( StrConst ) .getText ( ) = "\\" and
119
122
this .getArg ( 1 ) .asExpr ( ) .( StrConst ) .getText ( ) in [ "/" , "" ]
120
123
}
@@ -124,7 +127,7 @@ module UrlRedirect {
124
127
override predicate step (
125
128
DataFlow:: Node nodeFrom , FlowState stateFrom , DataFlow:: Node nodeTo , FlowState stateTo
126
129
) {
127
- nodeFrom = this . getObject ( ) and
130
+ nodeFrom = receiver and
128
131
stateFrom instanceof MayContainBackslashes and
129
132
nodeTo = this and
130
133
stateTo instanceof NoBackslashes
@@ -134,5 +137,10 @@ module UrlRedirect {
134
137
/**
135
138
* A comparison with a constant string, considered as a sanitizer-guard.
136
139
*/
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
+ }
138
146
}
0 commit comments