@@ -19,10 +19,13 @@ abstract class ActionMethod extends Method {
19
19
}
20
20
21
21
Callable getAnAuthorizingCallable ( ) { result = this }
22
+
23
+ string getARoute ( ) { result = this .getDeclaringType ( ) .getFile ( ) .getRelativePath ( ) }
22
24
}
23
25
24
26
private class MvcActionMethod extends ActionMethod {
25
27
MvcActionMethod ( ) { this = any ( MicrosoftAspNetCoreMvcController c ) .getAnActionMethod ( ) }
28
+ // override string getARoute() { none() }
26
29
}
27
30
28
31
private class WebFormActionMethod extends ActionMethod {
@@ -83,26 +86,38 @@ class AuthorizationXmlElement extends XmlElement {
83
86
result = path .getValue ( )
84
87
)
85
88
}
89
+
90
+ string getARoute ( ) {
91
+ result = this .getLocationTagPath ( )
92
+ or
93
+ result = this .getPhysicalPath ( ) + "/" + this .getLocationTagPath ( )
94
+ or
95
+ not exists ( this .getLocationTagPath ( ) ) and
96
+ result = this .getPhysicalPath ( )
97
+ }
86
98
}
87
99
88
100
/**
89
101
* Holds if the given action has an xml `authorization` tag that refers to it.
90
102
* TODO: Currently only supports physical paths, however virtual paths defined by `AddRoute` can also be used.
91
103
*/
92
104
predicate hasAuthViaXml ( ActionMethod m ) {
93
- exists ( AuthorizationXmlElement el , string path , string rest |
94
- path = ( el .getPhysicalPath ( ) + "/" + el .getLocationTagPath ( ) )
95
- or
96
- not exists ( el .getLocationTagPath ( ) ) and
97
- path = el .getPhysicalPath ( )
98
- |
105
+ exists ( AuthorizationXmlElement el , string rest |
99
106
el .hasDenyElement ( ) and
100
- m .getDeclaringType ( ) . getFile ( ) . getRelativePath ( ) = path + rest
107
+ m .getARoute ( ) = el . getARoute ( ) + rest
101
108
)
102
109
}
103
110
111
+ predicate hasAuthViaAttribute ( ActionMethod m ) {
112
+ [ m .getAnAttribute ( ) , m .getDeclaringType ( ) .getAnAttribute ( ) ]
113
+ .getType ( )
114
+ .hasQualifiedName ( "Microsoft.AspNetCore.Authorization" , "AuthorizeAttribute" )
115
+ }
116
+
104
117
/** Holds if `m` is a method that should have an auth check, but is missing it. */
105
118
predicate missingAuth ( ActionMethod m ) {
106
119
m .needsAuth ( ) and
107
- not hasAuthViaCode ( m )
120
+ not hasAuthViaCode ( m ) and
121
+ not hasAuthViaXml ( m ) and
122
+ not hasAuthViaAttribute ( m )
108
123
}
0 commit comments