@@ -19,10 +19,13 @@ abstract class ActionMethod extends Method {
1919 }
2020
2121 Callable getAnAuthorizingCallable ( ) { result = this }
22+
23+ string getARoute ( ) { result = this .getDeclaringType ( ) .getFile ( ) .getRelativePath ( ) }
2224}
2325
2426private class MvcActionMethod extends ActionMethod {
2527 MvcActionMethod ( ) { this = any ( MicrosoftAspNetCoreMvcController c ) .getAnActionMethod ( ) }
28+ // override string getARoute() { none() }
2629}
2730
2831private class WebFormActionMethod extends ActionMethod {
@@ -83,26 +86,38 @@ class AuthorizationXmlElement extends XmlElement {
8386 result = path .getValue ( )
8487 )
8588 }
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+ }
8698}
8799
88100/**
89101 * Holds if the given action has an xml `authorization` tag that refers to it.
90102 * TODO: Currently only supports physical paths, however virtual paths defined by `AddRoute` can also be used.
91103 */
92104predicate 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 |
99106 el .hasDenyElement ( ) and
100- m .getDeclaringType ( ) . getFile ( ) . getRelativePath ( ) = path + rest
107+ m .getARoute ( ) = el . getARoute ( ) + rest
101108 )
102109}
103110
111+ predicate hasAuthViaAttribute ( ActionMethod m ) {
112+ [ m .getAnAttribute ( ) , m .getDeclaringType ( ) .getAnAttribute ( ) ]
113+ .getType ( )
114+ .hasQualifiedName ( "Microsoft.AspNetCore.Authorization" , "AuthorizeAttribute" )
115+ }
116+
104117/** Holds if `m` is a method that should have an auth check, but is missing it. */
105118predicate missingAuth ( ActionMethod m ) {
106119 m .needsAuth ( ) and
107- not hasAuthViaCode ( m )
120+ not hasAuthViaCode ( m ) and
121+ not hasAuthViaXml ( m ) and
122+ not hasAuthViaAttribute ( m )
108123}
0 commit comments