Skip to content

Commit 582c4a7

Browse files
Support virtual route mappings for webforms actions
1 parent 63b3e16 commit 582c4a7

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

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

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ abstract class ActionMethod extends Method {
1515
}
1616

1717
predicate needsAuth() {
18-
this.getADescription().toLowerCase().regexpMatch(".*(edit|delete|modify|admin|superuser).*")
18+
this.getADescription()
19+
.regexpReplaceAll("([a-z])([A-Z])", "$1_$2")
20+
.toLowerCase()
21+
.regexpMatch(".*(edit|delete|modify|admin|superuser).*")
1922
}
2023

2124
Callable getAnAuthorizingCallable() { result = this }
@@ -40,6 +43,38 @@ private class WebFormActionMethod extends ActionMethod {
4043
result.getDeclaringType() = this.getDeclaringType() and
4144
result.getName() = "Page_Load"
4245
}
46+
47+
override string getARoute() {
48+
exists(string physicalRoute | physicalRoute = super.getARoute() |
49+
result = physicalRoute
50+
or
51+
exists(string absolutePhysical |
52+
virtualRouteMapping(result, absolutePhysical) and
53+
physicalRouteMatches(absolutePhysical, physicalRoute)
54+
)
55+
)
56+
}
57+
}
58+
59+
private predicate virtualRouteMapping(string virtualRoute, string physicalRoute) {
60+
exists(MethodCall mapPageRouteCall, StringLiteral virtualLit, StringLiteral physicalLit |
61+
mapPageRouteCall
62+
.getTarget()
63+
.hasQualifiedName("System.Web.Routing", "RouteCollection", "MapPageRoute") and
64+
virtualLit = mapPageRouteCall.getArgument(1) and
65+
physicalLit = mapPageRouteCall.getArgument(2) and
66+
virtualLit.getValue() = virtualRoute and
67+
physicalLit.getValue() = physicalRoute
68+
// physicalRouteMatches(physicalLit.getValue(), physicalRoute)
69+
)
70+
}
71+
72+
bindingset[route, actual]
73+
private predicate physicalRouteMatches(string route, string actual) {
74+
route = actual
75+
or
76+
route.charAt(0) = "~" and
77+
exists(string dir | actual = dir + route.substring(1, route.length()) + ".cs")
4378
}
4479

4580
/** An expression that indicates that some authorization/authentication check is being performed. */

0 commit comments

Comments
 (0)