Skip to content

Commit a1a93c7

Browse files
authored
Merge pull request #16304 from hvitved/csharp/fix-bad-join
C#: Fix a bad join
2 parents 3592e76 + d8d7688 commit a1a93c7

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

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

+14-6
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,21 @@ import semmle.code.csharp.frameworks.system.Web
1616
import semmle.code.csharp.frameworks.system.web.Helpers
1717
import semmle.code.csharp.frameworks.system.web.Mvc
1818

19+
private Method getAValidatingMethod() {
20+
result = any(AntiForgeryClass a).getValidateMethod()
21+
or
22+
result.calls(getAValidatingMethod())
23+
}
24+
1925
/** An `AuthorizationFilter` that calls the `AntiForgery.Validate` method. */
2026
class AntiForgeryAuthorizationFilter extends AuthorizationFilter {
21-
AntiForgeryAuthorizationFilter() {
22-
this.getOnAuthorizationMethod().calls*(any(AntiForgeryClass a).getValidateMethod())
23-
}
27+
AntiForgeryAuthorizationFilter() { this.getOnAuthorizationMethod() = getAValidatingMethod() }
28+
}
29+
30+
private Method getAStartedMethod() {
31+
result = any(WebApplication wa).getApplication_StartMethod()
32+
or
33+
getAStartedMethod().calls(result)
2434
}
2535

2636
/**
@@ -34,9 +44,7 @@ predicate hasGlobalAntiForgeryFilter() {
3444
// The filter is an antiforgery filter
3545
addGlobalFilter.getArgumentForName("filter").getType() instanceof AntiForgeryAuthorizationFilter and
3646
// The filter is added by the Application_Start() method
37-
any(WebApplication wa)
38-
.getApplication_StartMethod()
39-
.calls*(addGlobalFilter.getEnclosingCallable())
47+
getAStartedMethod() = addGlobalFilter.getEnclosingCallable()
4048
)
4149
}
4250

0 commit comments

Comments
 (0)