Skip to content

Commit 26e3967

Browse files
Jami CogswellJami Cogswell
authored andcommitted
Java: edit qhelp
1 parent 53cb30d commit 26e3967

File tree

3 files changed

+39
-39
lines changed

3 files changed

+39
-39
lines changed
Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
@Configuration(proxyBeanMethods = false)
2-
public class SpringBootActuators extends WebSecurityConfigurerAdapter {
2+
public class CustomSecurityConfiguration {
3+
4+
@Bean
5+
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
6+
// BAD: Unauthenticated access to Spring Boot actuator endpoints is allowed
7+
http.securityMatcher(EndpointRequest.toAnyEndpoint());
8+
http.authorizeHttpRequests((requests) -> requests.anyRequest().permitAll());
9+
return http.build();
10+
}
311

4-
@Override
5-
protected void configure(HttpSecurity http) throws Exception {
6-
// BAD: Unauthenticated access to Spring Boot actuator endpoints is allowed
7-
http.requestMatcher(EndpointRequest.toAnyEndpoint()).authorizeRequests((requests) ->
8-
requests.anyRequest().permitAll());
9-
}
1012
}
1113

1214
@Configuration(proxyBeanMethods = false)
13-
public class ActuatorSecurity extends WebSecurityConfigurerAdapter {
15+
public class CustomSecurityConfiguration {
16+
17+
@Bean
18+
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
19+
// GOOD: only users with ENDPOINT_ADMIN role are allowed to access the actuator endpoints
20+
http.securityMatcher(EndpointRequest.toAnyEndpoint());
21+
http.authorizeHttpRequests((requests) -> requests.anyRequest().hasRole("ENDPOINT_ADMIN"));
22+
return http.build();
23+
}
1424

15-
@Override
16-
protected void configure(HttpSecurity http) throws Exception {
17-
// GOOD: only users with ENDPOINT_ADMIN role are allowed to access the actuator endpoints
18-
http.requestMatcher(EndpointRequest.toAnyEndpoint()).authorizeRequests((requests) ->
19-
requests.anyRequest().hasRole("ENDPOINT_ADMIN"));
20-
http.httpBasic();
21-
}
2225
}

java/ql/src/Security/CWE/CWE-200/SpringBootActuators.qhelp

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,24 @@
33
"qhelp.dtd">
44
<qhelp>
55
<overview>
6-
<p>Spring Boot includes a number of additional features called actuators that let you monitor
7-
and interact with your web application. Exposing unprotected actuator endpoints via JXM or HTTP
8-
can, however, lead to information disclosure or even to remote code execution vulnerability.</p>
6+
<p>Spring Boot includes features called actuators that let you monitor and interact with your
7+
web application. Exposing unprotected actuator endpoints can lead to information disclosure or
8+
even to remote code execution.</p>
99
</overview>
1010

1111
<recommendation>
12-
<p>Since actuator endpoints may contain sensitive information, careful consideration should be
13-
given about when to expose them. You should take care to secure exposed HTTP endpoints in the same
14-
way that you would any other sensitive URL. If Spring Security is present, endpoints are secured by
15-
default using Spring Security’s content-negotiation strategy. If you wish to configure custom
16-
security for HTTP endpoints, for example, only allow users with a certain role to access them,
17-
Spring Boot provides some convenient <code>RequestMatcher</code> objects that can be used in
18-
combination with Spring Security.</p>
12+
<p>Since actuator endpoints may contain sensitive information, carefully consider when to expose them,
13+
and secure them as you would any sensitive URL. Actuators are secured by default when using Spring
14+
Security without a custom configuration. If you wish to define a custom security configuration,
15+
consider only allowing users with certain roles access to the endpoints.
16+
</p>
17+
1918
</recommendation>
2019

2120
<example>
2221
<p>In the first example, the custom security configuration allows unauthenticated access to all
2322
actuator endpoints. This may lead to sensitive information disclosure and should be avoided.</p>
23+
2424
<p>In the second example, only users with <code>ENDPOINT_ADMIN</code> role are allowed to access
2525
the actuator endpoints.</p>
2626

@@ -29,11 +29,8 @@ the actuator endpoints.</p>
2929

3030
<references>
3131
<li>
32-
Spring Boot documentation:
33-
<a href="https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-features.html">Actuators</a>.
34-
</li>
35-
<li>
36-
<a href="https://www.veracode.com/blog/research/exploiting-spring-boot-actuators">Exploiting Spring Boot Actuators</a>
32+
Spring Boot Reference Documentation:
33+
<a href="https://docs.spring.io/spring-boot/reference/actuator/endpoints.html">Endpoints</a>.
3734
</li>
3835
</references>
3936
</qhelp>

java/ql/test/query-tests/security/CWE-200/semmle/tests/SpringBootActuators/SpringBootActuatorsTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -265,17 +265,17 @@ protected void configureOkNoPermitAll7_securityMatchers(HttpSecurity http) throw
265265
http.securityMatchers(matcher -> EndpointRequest.toAnyEndpoint()).authorizeHttpRequests().anyRequest();
266266
}
267267

268-
// Spring doc example
269-
// https://docs.spring.io/spring-boot/reference/actuator/endpoints.html#actuator.endpoints.security
270-
public void securityFilterChain(HttpSecurity http) throws Exception {
271-
http.securityMatcher(EndpointRequest.toAnyEndpoint());
272-
http.authorizeHttpRequests((requests) -> requests.anyRequest().permitAll()); // $ hasExposedSpringBootActuator
273-
}
268+
// QHelp Bad example
269+
public void securityFilterChain1(HttpSecurity http) throws Exception {
270+
// BAD: Unauthenticated access to Spring Boot actuator endpoints is allowed
271+
http.securityMatcher(EndpointRequest.toAnyEndpoint());
272+
http.authorizeHttpRequests((requests) -> requests.anyRequest().permitAll()); // $ hasExposedSpringBootActuator
273+
}
274274

275275
// QHelp Good example
276-
protected void configureQhelpGood(HttpSecurity http) throws Exception {
276+
public void securityFilterChain2(HttpSecurity http) throws Exception {
277277
// GOOD: only users with ENDPOINT_ADMIN role are allowed to access the actuator endpoints
278-
http.requestMatcher(EndpointRequest.toAnyEndpoint()).authorizeRequests((requests) ->
279-
requests.anyRequest().hasRole("ENDPOINT_ADMIN"));
278+
http.securityMatcher(EndpointRequest.toAnyEndpoint());
279+
http.authorizeHttpRequests((requests) -> requests.anyRequest().hasRole("ENDPOINT_ADMIN"));
280280
}
281281
}

0 commit comments

Comments
 (0)