@@ -122,10 +122,7 @@ private module Shared {
122
122
AssignExpr getAnAssignExpr ( ) { result .getLeftOperand ( ) = this .getExpr ( ) }
123
123
}
124
124
125
- /**
126
- * An additional step that is preserves dataflow in the context of XSS.
127
- */
128
- predicate isAdditionalXSSFlowStep ( DataFlow:: Node node1 , DataFlow:: Node node2 ) {
125
+ predicate isFlowFromLocals ( DataFlow:: Node node1 , DataFlow:: Node node2 ) {
129
126
// node1 is a `locals` argument to a render call...
130
127
exists ( RenderCall call , Pair kvPair , string hashKey |
131
128
call .getLocals ( ) .getAKeyValuePair ( ) = kvPair and
@@ -154,7 +151,9 @@ private module Shared {
154
151
)
155
152
)
156
153
)
157
- or
154
+ }
155
+
156
+ predicate isFlowFromControllerInstanceVariable ( DataFlow:: Node node1 , DataFlow:: Node node2 ) {
158
157
// instance variables in the controller
159
158
exists (
160
159
ActionControllerActionMethod action , VariableReadAccess viewVarRead , AssignExpr ae ,
@@ -169,7 +168,9 @@ private module Shared {
169
168
node1 .asExpr ( ) .getExpr ( ) = ae .getRightOperand ( ) and
170
169
ae .getParent + ( ) = action
171
170
)
172
- or
171
+ }
172
+
173
+ predicate isFlowIntoHelperMethod ( DataFlow:: Node node1 , DataFlow:: Node node2 ) {
173
174
// flow from template into controller helper method
174
175
exists (
175
176
ErbFile template , ActionControllerHelperMethod helperMethod ,
@@ -181,13 +182,16 @@ private module Shared {
181
182
helperMethodCall .getArgument ( argIdx ) = node1 .asExpr ( ) and
182
183
helperMethod .getParameter ( argIdx ) = node2 .asExpr ( ) .getExpr ( )
183
184
)
184
- or
185
+ }
186
+
187
+ predicate isFlowFromHelperMethod ( DataFlow:: Node node1 , DataFlow:: Node node2 ) {
185
188
// flow out of controller helper method into template
186
189
exists (
187
190
ErbFile template , ActionControllerHelperMethod helperMethod ,
188
191
CfgNodes:: ExprNodes:: MethodCallCfgNode helperMethodCall
189
192
|
190
193
template = node2 .getLocation ( ) .getFile ( ) and
194
+ // TODO: this is slow, x-product of helper method names and method calls
191
195
helperMethod .getName ( ) = helperMethodCall .getExpr ( ) .getMethodName ( ) and
192
196
helperMethod .getControllerClass ( ) = getAssociatedControllerClass ( template ) and
193
197
// `node1` is an expr node that may be returned by the helper method
@@ -196,6 +200,20 @@ private module Shared {
196
200
node2 .asExpr ( ) = helperMethodCall
197
201
)
198
202
}
203
+
204
+ /**
205
+ * An additional step that is preserves dataflow in the context of XSS.
206
+ */
207
+ pragma [ noopt]
208
+ predicate isAdditionalXSSFlowStep ( DataFlow:: Node node1 , DataFlow:: Node node2 ) {
209
+ isFlowFromLocals ( node1 , node2 )
210
+ or
211
+ isFlowFromControllerInstanceVariable ( node1 , node2 )
212
+ or
213
+ isFlowIntoHelperMethod ( node1 , node2 )
214
+ or
215
+ isFlowFromHelperMethod ( node1 , node2 )
216
+ }
199
217
}
200
218
201
219
/**
0 commit comments