Skip to content

Commit 8c512c4

Browse files
Jami CogswellJami Cogswell
authored andcommitted
Java: some refactoring
1 parent 8b0f943 commit 8c512c4

File tree

2 files changed

+54
-67
lines changed

2 files changed

+54
-67
lines changed

java/ql/lib/semmle/code/java/frameworks/spring/SpringSecurity.qll

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class TypeAbstractRequestMatcherRegistry extends Class {
4040
}
4141

4242
/**
43-
* A call to `HttpSecurity.authorizeRequests` method.
43+
* A call to the `HttpSecurity.authorizeRequests` method.
4444
*
4545
* Note: this API is deprecated and scheduled for removal
4646
* in Spring Security 7.0.
@@ -53,7 +53,7 @@ class AuthorizeRequestsCall extends MethodCall {
5353
}
5454

5555
/**
56-
* A call to `HttpSecurity.authorizeHttpRequests` method.
56+
* A call to the `HttpSecurity.authorizeHttpRequests` method.
5757
*
5858
* Note: the no-argument version of this API is deprecated
5959
* and scheduled for removal in Spring Security 7.0.
@@ -65,15 +65,47 @@ class AuthorizeHttpRequestsCall extends MethodCall {
6565
}
6666
}
6767

68-
/** A call to `AuthorizedUrl.permitAll` method. */
68+
/** A call to the `HttpSecurity.requestMatcher` method. */
69+
class RequestMatcherCall extends MethodCall {
70+
RequestMatcherCall() {
71+
this.getMethod().hasName("requestMatcher") and
72+
this.getMethod().getDeclaringType() instanceof TypeHttpSecurity
73+
}
74+
}
75+
76+
/** A call to the `HttpSecurity.requestMatchers` method. */
77+
class RequestMatchersCall extends MethodCall {
78+
RequestMatchersCall() {
79+
this.getMethod().hasName("requestMatchers") and
80+
this.getMethod().getDeclaringType() instanceof TypeHttpSecurity
81+
}
82+
}
83+
84+
/** A call to the `HttpSecurity.securityMatcher` method. */
85+
class SecurityMatcherCall extends MethodCall {
86+
SecurityMatcherCall() {
87+
this.getMethod().hasName("securityMatcher") and
88+
this.getMethod().getDeclaringType() instanceof TypeHttpSecurity
89+
}
90+
}
91+
92+
/** A call to the `HttpSecurity.securityMatchers` method. */
93+
class SecurityMatchersCall extends MethodCall {
94+
SecurityMatchersCall() {
95+
this.getMethod().hasName("securityMatchers") and
96+
this.getMethod().getDeclaringType() instanceof TypeHttpSecurity
97+
}
98+
}
99+
100+
/** A call to the `AuthorizedUrl.permitAll` method. */
69101
class PermitAllCall extends MethodCall {
70102
PermitAllCall() {
71103
this.getMethod().hasName("permitAll") and
72104
this.getMethod().getDeclaringType() instanceof TypeAuthorizedUrl
73105
}
74106
}
75107

76-
/** A call to `AbstractRequestMatcherRegistry.anyRequest` method. */
108+
/** A call to the `AbstractRequestMatcherRegistry.anyRequest` method. */
77109
class AnyRequestCall extends MethodCall {
78110
AnyRequestCall() {
79111
this.getMethod().hasName("anyRequest") and

java/ql/lib/semmle/code/java/security/SpringBootActuatorsQuery.qll

Lines changed: 18 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,36 @@ private import semmle.code.java.frameworks.spring.SpringSecurity
55
private 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 MatcherCall extends MethodCall {
12+
MatcherCall() {
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 MatchersCall extends MethodCall {
26+
MatchersCall() {
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
*/
3539
private class RegistryRequestMatchersCall extends MethodCall {
3640
RegistryRequestMatchersCall() {
@@ -40,63 +44,14 @@ 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. */
7148
private 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). */
10156
predicate permitsSpringBootActuators(PermitAllCall permitAllCall) {
10257
exists(AuthorizeCall authorizeCall |

0 commit comments

Comments
 (0)