@@ -5,32 +5,36 @@ private import semmle.code.java.frameworks.spring.SpringSecurity
5
5
private import semmle.code.java.frameworks.spring.SpringBoot
6
6
7
7
/**
8
- * A call to `HttpSecurity.requestMatcher` method with argument
8
+ * A call to an `HttpSecurity` matcher method with argument
9
9
* `EndpointRequest.toAnyEndpoint()`.
10
10
*/
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
15
17
this .getArgument ( 0 ) instanceof ToAnyEndpointCall
16
18
}
17
19
}
18
20
19
21
/**
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()`.
22
24
*/
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
27
31
this .getArgument ( 0 ) .( LambdaExpr ) .getExprBody ( ) instanceof ToAnyEndpointCall
28
32
}
29
33
}
30
34
31
35
/**
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()`.
34
38
*/
35
39
private class RegistryRequestMatchersCall extends MethodCall {
36
40
RegistryRequestMatchersCall ( ) {
@@ -40,71 +44,22 @@ private class RegistryRequestMatchersCall extends MethodCall {
40
44
}
41
45
}
42
46
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. */
71
48
private class AuthorizeCall extends MethodCall {
72
49
AuthorizeCall ( ) {
73
50
this instanceof AuthorizeRequestsCall or
74
51
this instanceof AuthorizeHttpRequestsCall
75
52
}
76
53
}
77
54
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
-
100
55
/** Holds if `permitAllCall` is called on request(s) mapped to actuator endpoint(s). */
101
56
predicate permitsSpringBootActuators ( PermitAllCall permitAllCall ) {
102
57
exists ( AuthorizeCall authorizeCall |
103
58
// .requestMatcher(EndpointRequest).authorizeRequests([...]).[...]
104
- authorizeCall .getQualifier ( ) instanceof MatcherCall
59
+ authorizeCall .getQualifier ( ) instanceof HttpSecurityMatcherCall
105
60
or
106
61
// .requestMatchers(matcher -> EndpointRequest).authorizeRequests([...]).[...]
107
- authorizeCall .getQualifier ( ) instanceof MatchersCall
62
+ authorizeCall .getQualifier ( ) instanceof HttpSecurityMatchersCall
108
63
|
109
64
// [...].authorizeRequests(r -> r.anyRequest().permitAll()) or
110
65
// [...].authorizeRequests(r -> r.requestMatchers(EndpointRequest).permitAll())
@@ -143,7 +98,7 @@ predicate permitsSpringBootActuators(PermitAllCall permitAllCall) {
143
98
permitAllCall .getQualifier ( ) = registryRequestMatchersCall
144
99
)
145
100
or
146
- exists ( Variable v , MatcherCall matcherCall |
101
+ exists ( Variable v , HttpSecurityMatcherCall matcherCall |
147
102
// http.securityMatcher(EndpointRequest.toAnyEndpoint());
148
103
// http.authorizeRequests([...].permitAll())
149
104
v .getAnAccess ( ) = authorizeCall .getQualifier ( ) and
0 commit comments