Skip to content

Commit 62fb693

Browse files
committed
C#: Tidy up code and fix performance of remote flow sources.
1 parent 2090d69 commit 62fb693

File tree

4 files changed

+129
-175
lines changed

4 files changed

+129
-175
lines changed

csharp/ql/src/semmle/code/csharp/dataflow/flowsources/Remote.qll

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,7 @@ class MicrosoftOwinStringFlowSource extends RemoteFlowSource, DataFlow::ExprNode
143143
string getSourceType() { result = "Microsoft Owin request or query string" }
144144
}
145145

146-
/**
147-
* A data flow source of remote user input (`Microsoft Owin IOwinRequest`).
148-
*/
146+
/** A data flow source of remote user input (`Microsoft Owin IOwinRequest`). */
149147
class MicrosoftOwinRequestRemoteFlowSource extends RemoteFlowSource, DataFlow::ExprNode {
150148
MicrosoftOwinRequestRemoteFlowSource() {
151149
exists(Property p, MicrosoftOwinIOwinRequestClass owinRequest |
@@ -174,15 +172,14 @@ class MicrosoftOwinRequestRemoteFlowSource extends RemoteFlowSource, DataFlow::E
174172
string getSourceType() { result = "Microsoft Owin request" }
175173
}
176174

177-
/**
178-
* A parameter to an Mvc controller action method, viewed as a source of remote user input.
179-
*/
175+
/** A parameter to an Mvc controller action method, viewed as a source of remote user input. */
180176
class ActionMethodParameter extends RemoteFlowSource, DataFlow::ParameterNode {
181177
ActionMethodParameter() {
182178
exists(Parameter p |
183179
p = this.getParameter() and
184180
p.fromSource() |
185-
p = any(Controller c).getAnActionMethod().getAParameter() or
181+
p = any(Controller c).getAnActionMethod().getAParameter()
182+
or
186183
p = any(ApiController c).getAnActionMethod().getAParameter()
187184
)
188185
}
@@ -198,29 +195,30 @@ abstract class AspNetCoreRemoteFlowSource extends RemoteFlowSource { }
198195
/** A data flow source of remote user input (ASP.NET query collection). */
199196
class AspNetCoreQueryRemoteFlowSource extends AspNetCoreRemoteFlowSource, DataFlow::ExprNode {
200197
AspNetCoreQueryRemoteFlowSource() {
201-
exists(ValueOrRefType t, Call c, Access ac |
202-
t instanceof MicrosoftAspNetCoreHttpHttpRequest or
203-
t instanceof MicrosoftAspNetCoreHttpQueryCollection or
204-
t instanceof MicrosoftAspNetCoreHttpQueryString |
205-
this.getExpr() = c and
206-
c.getTarget().getDeclaringType() = t
198+
exists(ValueOrRefType t |
199+
t instanceof MicrosoftAspNetCoreHttpHttpRequest
200+
or
201+
t instanceof MicrosoftAspNetCoreHttpQueryCollection
207202
or
208-
this.asExpr() = ac and
209-
ac.getTarget().getDeclaringType() = t
203+
t instanceof MicrosoftAspNetCoreHttpQueryString
204+
|
205+
this.getExpr().(Call).getTarget().getDeclaringType() = t
210206
or
211-
c.getTarget().getDeclaringType().hasQualifiedName("Microsoft.AspNetCore.Http", "IQueryCollection") and
212-
c.getTarget().getName() = "TryGetValue" and
213-
this.asExpr() = c.getArgumentForName("value")
207+
this.asExpr().(Access).getTarget().getDeclaringType() = t
208+
)
209+
or
210+
exists(Call c |
211+
c.getTarget().getDeclaringType().hasQualifiedName("Microsoft.AspNetCore.Http", "IQueryCollection") and
212+
c.getTarget().getName() = "TryGetValue" and
213+
this.asExpr() = c.getArgumentForName("value")
214214
)
215215
}
216216

217217
override
218218
string getSourceType() { result = "ASP.NET Core query string" }
219219
}
220220

221-
/**
222-
* A parameter to an Mvc controller action method, viewed as a source of remote user input.
223-
*/
221+
/** A parameter to a `Mvc` controller action method, viewed as a source of remote user input. */
224222
class AspNetCoreActionMethodParameter extends RemoteFlowSource, DataFlow::ParameterNode {
225223
AspNetCoreActionMethodParameter() {
226224
exists(Parameter p |

0 commit comments

Comments
 (0)