Skip to content

Commit a2dce6b

Browse files
Check for authorize attributes in more namespaces and on overridden methods
1 parent 6a95ed6 commit a2dce6b

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

csharp/ql/lib/semmle/code/csharp/security/auth/InsecureDirectObjectReferenceQuery.qll

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@ private predicate hasAuthorizeAttribute(ActionMethod m) {
4444
exists(Attribute attr |
4545
attr.getType()
4646
.getABaseType*()
47-
.hasQualifiedName("Microsoft.AspNetCore.Authorization", "AuthorizeAttribute")
47+
.hasQualifiedName([
48+
"Microsoft.AspNetCore.Authorization", "System.Web.Mvc", "System.Web.Http"
49+
], "AuthorizeAttribute")
4850
|
49-
attr = m.getAnAttribute() or
51+
attr = m.getOverridee*().getAnAttribute() or
5052
attr = m.getDeclaringType().getABaseType*().getAnAttribute()
5153
)
5254
}
@@ -56,14 +58,16 @@ private predicate hasAllowAnonymousAttribute(ActionMethod m) {
5658
exists(Attribute attr |
5759
attr.getType()
5860
.getABaseType*()
59-
.hasQualifiedName("Microsoft.AspNetCore.Authorization", "AllowAnonymousAttribute")
61+
.hasQualifiedName([
62+
"Microsoft.AspNetCore.Authorization", "System.Web.Mvc", "System.Web.Http"
63+
], "AllowAnonymousAttribute")
6064
|
61-
attr = m.getAnAttribute() or
65+
attr = m.getOverridee*().getAnAttribute() or
6266
attr = m.getDeclaringType().getABaseType*().getAnAttribute()
6367
)
6468
}
6569

66-
/** Hols if `m` is authorized via an `Authorize` attribute */
70+
/** Holds if `m` is authorized via an `Authorize` attribute */
6771
private predicate isAuthorizedViaAttribute(ActionMethod m) {
6872
hasAuthorizeAttribute(m) and
6973
not hasAllowAnonymousAttribute(m)

0 commit comments

Comments
 (0)