Skip to content

Commit 7020363

Browse files
authored
Merge pull request #9393 from michaelnebel/csharp/asptaintedmember
C#: ASP.NET Core like members are tainted
2 parents edf0be0 + 9211d75 commit 7020363

File tree

8 files changed

+63
-2
lines changed

8 files changed

+63
-2
lines changed

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,23 @@ 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+
/**
175+
* Data flow for AST.NET Core.
176+
*
177+
* Flow is defined from any ASP.NET Core remote source object to any of its member
178+
* properties.
179+
*/
180+
private class AspNetCoreRemoteFlowSourceMember extends TaintTracking::TaintedMember {
181+
AspNetCoreRemoteFlowSourceMember() {
182+
this.getDeclaringType() = any(AspNetCoreRemoteFlowSource source).getType() and
183+
this.isPublic() and
184+
not this.isStatic() and
185+
exists(Property p | p = this |
186+
p.isAutoImplemented() and p.getGetter().isPublic() and p.getSetter().isPublic()
187+
)
188+
}
189+
}
190+
174191
/** A data flow source of remote user input (ASP.NET query collection). */
175192
class AspNetCoreQueryRemoteFlowSource extends AspNetCoreRemoteFlowSource, DataFlow::ExprNode {
176193
AspNetCoreQueryRemoteFlowSource() {
@@ -196,7 +213,7 @@ class AspNetCoreQueryRemoteFlowSource extends AspNetCoreRemoteFlowSource, DataFl
196213
}
197214

198215
/** A parameter to a `Mvc` controller action method, viewed as a source of remote user input. */
199-
class AspNetCoreActionMethodParameter extends RemoteFlowSource, DataFlow::ParameterNode {
216+
class AspNetCoreActionMethodParameter extends AspNetCoreRemoteFlowSource, DataFlow::ParameterNode {
200217
AspNetCoreActionMethodParameter() {
201218
exists(Parameter p |
202219
p = this.getParameter() and
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* All auto implemented public properties with public getters and setters on ASP.NET Core remote flow sources are now also considered to be tainted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
3+
namespace Testing
4+
{
5+
6+
public class ViewModel
7+
{
8+
public string RequestId { get; set; } // Considered tainted.
9+
public object RequestIdField; // Not considered tainted as it is a field.
10+
public string RequestIdOnlyGet { get; } // Not considered tainted as there is no setter.
11+
public string RequestIdPrivateSet { get; private set; } // Not considered tainted as it has a private setter.
12+
public static object RequestIdStatic { get; set; } // Not considered tainted as it is static.
13+
private string RequestIdPrivate { get; set; } // Not considered tainted as it is private.
14+
}
15+
16+
public class TestController : Controller
17+
{
18+
public object MyAction(ViewModel viewModel)
19+
{
20+
throw null;
21+
}
22+
}
23+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
remoteFlowSourceMembers
2+
| AspRemoteFlowSource.cs:8:23:8:31 | RequestId |
3+
remoteFlowSources
4+
| AspRemoteFlowSource.cs:18:42:18:50 | viewModel |
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import csharp
2+
import semmle.code.csharp.security.dataflow.flowsources.Remote
3+
4+
query predicate remoteFlowSourceMembers(TaintTracking::TaintedMember m) { m.fromSource() }
5+
6+
query predicate remoteFlowSources(AspNetCoreRemoteFlowSource s) {
7+
s.getEnclosingCallable().fromSource()
8+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
semmle-extractor-options: /nostdlib /noconfig
2+
semmle-extractor-options: --load-sources-from-project:${testdir}/../../../../resources/stubs/_frameworks/Microsoft.NETCore.App/Microsoft.NETCore.App.csproj
3+
semmle-extractor-options: --load-sources-from-project:${testdir}/../../../../resources/stubs/Microsoft.Extensions.Primitives/6.0.0/Microsoft.Extensions.Primitives.csproj
4+
semmle-extractor-options: ${testdir}/../../../../resources/stubs/AspNetCore.cs
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
semmle-extractor-options: /nostdlib /noconfig
22
semmle-extractor-options: --load-sources-from-project:${testdir}/../../../../resources/stubs/_frameworks/Microsoft.NETCore.App/Microsoft.NETCore.App.csproj
3-
semmle-extractor-options: --load-sources-from-project:${testdir}/../../../../resources/stubs/Microsoft.Extensions.Primitives/6.0.0/Microsoft.Extensions.Primitives.csproj
3+
semmle-extractor-options: --load-sources-from-project:${testdir}/../../../../resources/stubs/Microsoft.Extensions.Primitives/6.0.0/Microsoft.Extensions.Primitives.csproj
4+
semmle-extractor-options: ${testdir}/../../../../resources/stubs/AspNetCore.cs

0 commit comments

Comments
 (0)