Skip to content

Commit bd6d3c7

Browse files
committed
C#: Consider parameters passed to lambdas in MapGet remote flow sources.
1 parent c8afb1b commit bd6d3c7

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

csharp/ql/lib/semmle/code/csharp/frameworks/microsoft/AspNetCore.qll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,3 +357,15 @@ class MicrosoftAspNetCoreHttpHtmlString extends Class {
357357
this.hasQualifiedName("Microsoft.AspNetCore.Html", "HtmlString")
358358
}
359359
}
360+
361+
/**
362+
* The `Microsoft.AspNetCore.Builder.EndpointRouteBuilderExtensions` class.
363+
*/
364+
class MicrosoftAspNetCoreBuilderEndpointRouteBuilderExtensions extends Class {
365+
MicrosoftAspNetCoreBuilderEndpointRouteBuilderExtensions() {
366+
this.hasQualifiedName("Microsoft.AspNetCore.Builder", "EndpointRouteBuilderExtensions")
367+
}
368+
369+
/** Gets the `UseMap` extension method. */
370+
Method getMapGetMethod() { result = this.getAMethod("MapGet") }
371+
}

csharp/ql/lib/semmle/code/csharp/security/dataflow/flowsources/Remote.qll

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,22 @@ class ActionMethodParameter extends RemoteFlowSource, DataFlow::ParameterNode {
171171
/** A data flow source of remote user input (ASP.NET Core). */
172172
abstract class AspNetCoreRemoteFlowSource extends RemoteFlowSource { }
173173

174+
/** A parameter to a routing method delegate. */
175+
class RoutingMethodParameter extends AspNetCoreRemoteFlowSource, DataFlow::ParameterNode {
176+
RoutingMethodParameter() {
177+
exists(Parameter p, MethodCall m |
178+
p = this.getParameter() and
179+
p.fromSource()
180+
|
181+
m.getTarget() =
182+
any(MicrosoftAspNetCoreBuilderEndpointRouteBuilderExtensions c).getMapGetMethod() and
183+
p = m.getArgument(2).(AnonymousFunctionExpr).getAParameter()
184+
)
185+
}
186+
187+
override string getSourceType() { result = "ASP.NET Core routing endpoint." }
188+
}
189+
174190
/**
175191
* Data flow for ASP.NET Core.
176192
*

csharp/ql/test/library-tests/dataflow/flowsources/aspremote/aspRemoteFlowSource.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ remoteFlowSourceMembers
22
| AspRemoteFlowSource.cs:9:23:9:31 | RequestId |
33
remoteFlowSources
44
| AspRemoteFlowSource.cs:19:42:19:50 | viewModel |
5+
| AspRemoteFlowSource.cs:34:58:34:63 | newUrl |

0 commit comments

Comments
 (0)