Skip to content

Commit c272bf9

Browse files
committed
C#: Add support the generic version of specifying auto validate.
1 parent 349cd74 commit c272bf9

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ class MicrosoftAspNetCoreMvcFilterCollection extends Class {
173173

174174
/** Gets an `Add` method. */
175175
Method getAddMethod() {
176-
result = this.getAMethod("Add") or
177-
result = this.getABaseType().getAMethod("Add")
176+
result = this.getAMethod(["Add", "Add`1"]) or
177+
result = this.getABaseType().getAMethod(["Add", "Add`1"])
178178
}
179179
}
180180

csharp/ql/src/Security Features/CWE-352/MissingAntiForgeryTokenValidation.ql

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,15 @@ private predicate hasGlobalWebMvcAntiforgeryFilter(Compilation compilation) {
4949

5050
predicate hasGlobalAspNetMvcAntiForgeryFilter(Compilation compilation) {
5151
exists(MethodCall addGlobalFilter, MethodCall registrationCall |
52-
addGlobalFilter.getTarget() =
52+
addGlobalFilter.getTarget().getUnboundDeclaration() =
5353
any(AspNetCore::MicrosoftAspNetCoreMvcFilterCollection collection).getAddMethod() and
5454
// The filter is the `AutoValidateAntiforgeryTokenAttribute` filter.
55-
addGlobalFilter.getArgument(0).getType() instanceof
56-
AspNetCore::AutoValidateAntiforgeryTokenAttribute and
55+
(
56+
addGlobalFilter.getArgument(0).getType() instanceof
57+
AspNetCore::AutoValidateAntiforgeryTokenAttribute or
58+
addGlobalFilter.getTarget().(ConstructedGeneric).getTypeArgument(0) instanceof
59+
AspNetCore::AutoValidateAntiforgeryTokenAttribute
60+
) and
5761
// The filter is added in an ASP.NET Core registration call, which is provided as a lambda argument
5862
// to the Mvc registration method.
5963
registrationCall.getTarget() instanceof AspNetCore::MicrosoftAspNetCoreMvcRegistration and

0 commit comments

Comments
 (0)