@@ -5,32 +5,36 @@ private import semmle.code.java.frameworks.spring.SpringSecurity
55private import semmle.code.java.frameworks.spring.SpringBoot
66
77/**
8- * A call to `HttpSecurity.requestMatcher` method with argument
8+ * A call to an `HttpSecurity` matcher method with argument
99 * `EndpointRequest.toAnyEndpoint()`.
1010 */
11- private class RequestMatcherCall extends MethodCall {
12- RequestMatcherCall ( ) {
13- this .getMethod ( ) .hasName ( "requestMatcher" ) and
14- this .getMethod ( ) .getDeclaringType ( ) instanceof TypeHttpSecurity and
11+ private class HttpSecurityMatcherCall extends MethodCall {
12+ HttpSecurityMatcherCall ( ) {
13+ (
14+ this instanceof RequestMatcherCall or
15+ this instanceof SecurityMatcherCall
16+ ) and
1517 this .getArgument ( 0 ) instanceof ToAnyEndpointCall
1618 }
1719}
1820
1921/**
20- * A call to `HttpSecurity.requestMatchers` method with lambda argument
21- * `EndpointRequest.toAnyEndpoint()`.
22+ * A call to an `HttpSecurity` matchers method with lambda
23+ * argument `EndpointRequest.toAnyEndpoint()`.
2224 */
23- private class RequestMatchersCall extends MethodCall {
24- RequestMatchersCall ( ) {
25- this .getMethod ( ) .hasName ( "requestMatchers" ) and
26- this .getMethod ( ) .getDeclaringType ( ) instanceof TypeHttpSecurity and
25+ private class HttpSecurityMatchersCall extends MethodCall {
26+ HttpSecurityMatchersCall ( ) {
27+ (
28+ this instanceof RequestMatchersCall or
29+ this instanceof SecurityMatchersCall
30+ ) and
2731 this .getArgument ( 0 ) .( LambdaExpr ) .getExprBody ( ) instanceof ToAnyEndpointCall
2832 }
2933}
3034
3135/**
32- * A call to `AbstractRequestMatcherRegistry.requestMatchers` method with an argument
33- * `RequestMatcher .toAnyEndpoint()`.
36+ * A call to an `AbstractRequestMatcherRegistry.requestMatchers` method with
37+ * argument `EndpointRequest .toAnyEndpoint()`.
3438 */
3539private class RegistryRequestMatchersCall extends MethodCall {
3640 RegistryRequestMatchersCall ( ) {
@@ -40,71 +44,22 @@ private class RegistryRequestMatchersCall extends MethodCall {
4044 }
4145}
4246
43- /**
44- * A call to `HttpSecurity.securityMatcher` method with argument
45- * `EndpointRequest.toAnyEndpoint()`.
46- */
47- private class SecurityMatcherCall extends MethodCall {
48- SecurityMatcherCall ( ) {
49- this .getMethod ( ) .hasName ( "securityMatcher" ) and
50- this .getMethod ( ) .getDeclaringType ( ) instanceof TypeHttpSecurity and
51- this .getArgument ( 0 ) instanceof ToAnyEndpointCall
52- }
53- }
54-
55- /**
56- * A call to `HttpSecurity.securityMatchers` method with lambda argument
57- * `EndpointRequest.toAnyEndpoint()`.
58- */
59- private class SecurityMatchersCall extends MethodCall {
60- SecurityMatchersCall ( ) {
61- this .getMethod ( ) .hasName ( "securityMatchers" ) and
62- this .getMethod ( ) .getDeclaringType ( ) instanceof TypeHttpSecurity and
63- this .getArgument ( 0 ) .( LambdaExpr ) .getExprBody ( ) instanceof ToAnyEndpointCall
64- }
65- }
66-
67- /**
68- * A call to a method that authorizes requests, e.g. `authorizeRequests` or
69- * `authorizeHttpRequests`.
70- */
47+ /** A call to an `HttpSecurity` method that authorizes requests. */
7148private class AuthorizeCall extends MethodCall {
7249 AuthorizeCall ( ) {
7350 this instanceof AuthorizeRequestsCall or
7451 this instanceof AuthorizeHttpRequestsCall
7552 }
7653}
7754
78- /**
79- * A call to a matcher method with argument
80- * `EndpointRequest.toAnyEndpoint()`.
81- */
82- private class MatcherCall extends MethodCall {
83- MatcherCall ( ) {
84- this instanceof RequestMatcherCall or
85- this instanceof SecurityMatcherCall
86- }
87- }
88-
89- /**
90- * A call to a matchers method with argument
91- * `EndpointRequest.toAnyEndpoint()`.
92- */
93- private class MatchersCall extends MethodCall {
94- MatchersCall ( ) {
95- this instanceof RequestMatchersCall or
96- this instanceof SecurityMatchersCall
97- }
98- }
99-
10055/** Holds if `permitAllCall` is called on request(s) mapped to actuator endpoint(s). */
10156predicate permitsSpringBootActuators ( PermitAllCall permitAllCall ) {
10257 exists ( AuthorizeCall authorizeCall |
10358 // .requestMatcher(EndpointRequest).authorizeRequests([...]).[...]
104- authorizeCall .getQualifier ( ) instanceof MatcherCall
59+ authorizeCall .getQualifier ( ) instanceof HttpSecurityMatcherCall
10560 or
10661 // .requestMatchers(matcher -> EndpointRequest).authorizeRequests([...]).[...]
107- authorizeCall .getQualifier ( ) instanceof MatchersCall
62+ authorizeCall .getQualifier ( ) instanceof HttpSecurityMatchersCall
10863 |
10964 // [...].authorizeRequests(r -> r.anyRequest().permitAll()) or
11065 // [...].authorizeRequests(r -> r.requestMatchers(EndpointRequest).permitAll())
@@ -143,7 +98,7 @@ predicate permitsSpringBootActuators(PermitAllCall permitAllCall) {
14398 permitAllCall .getQualifier ( ) = registryRequestMatchersCall
14499 )
145100 or
146- exists ( Variable v , MatcherCall matcherCall |
101+ exists ( Variable v , HttpSecurityMatcherCall matcherCall |
147102 // http.securityMatcher(EndpointRequest.toAnyEndpoint());
148103 // http.authorizeRequests([...].permitAll())
149104 v .getAnAccess ( ) = authorizeCall .getQualifier ( ) and
0 commit comments