Skip to content

Commit a8bb798

Browse files
Jami CogswellJami Cogswell
authored andcommitted
Java: edit qhelp
1 parent 2438aba commit a8bb798

File tree

3 files changed

+30
-30
lines changed

3 files changed

+30
-30
lines changed
Lines changed: 16 additions & 13 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 {
33

4-
@Override
5-
protected void configure(HttpSecurity http) throws Exception {
4+
@Bean
5+
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
66
// BAD: Unauthenticated access to Spring Boot actuator endpoints is allowed
7-
http.requestMatcher(EndpointRequest.toAnyEndpoint()).authorizeRequests((requests) ->
8-
requests.anyRequest().permitAll());
9-
}
7+
http.securityMatcher(EndpointRequest.toAnyEndpoint());
8+
http.authorizeHttpRequests((requests) -> requests.anyRequest().permitAll());
9+
return http.build();
10+
}
11+
1012
}
1113

1214
@Configuration(proxyBeanMethods = false)
13-
public class ActuatorSecurity extends WebSecurityConfigurerAdapter {
15+
public class CustomSecurityConfiguration {
1416

15-
@Override
16-
protected void configure(HttpSecurity http) throws Exception {
17+
@Bean
18+
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
1719
// 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-
}
20+
http.securityMatcher(EndpointRequest.toAnyEndpoint());
21+
http.authorizeHttpRequests((requests) -> requests.anyRequest().hasRole("ENDPOINT_ADMIN"));
22+
return http.build();
23+
}
24+
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ public void securityFilterChain(HttpSecurity http) throws Exception {
275275
// QHelp Good example
276276
protected void configureQhelpGood(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)