Skip to content

Commit d7ae0f3

Browse files
committed
Ensure that management endpoints with nested paths are secured
Previously each endpoint was secured for path, path/, and path.*. This meant that a request to path/foo was not secured. This commit secures path/** to ensure that requests to a nested endpoint path are also secured. Fixes gh-2476
1 parent 6aaa5ee commit d7ae0f3

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ManagementSecurityAutoConfiguration.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2014 the original author or authors.
2+
* Copyright 2012-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -69,6 +69,7 @@
6969
* used as a security hint by the filter created here.
7070
*
7171
* @author Dave Syer
72+
* @author Andy Wilkinson
7273
*/
7374
@Configuration
7475
@ConditionalOnClass({ EnableWebSecurity.class })
@@ -243,8 +244,9 @@ private static String[] getEndpointPaths(
243244
String path = endpointHandlerMapping.getPrefix() + endpoint.getPath();
244245
paths.add(path);
245246
if (secure) {
247+
// Ensure the nested paths are secured
248+
paths.add(path + "/**");
246249
// Add Spring MVC-generated additional paths
247-
paths.add(path + "/");
248250
paths.add(path + ".*");
249251
}
250252
}

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/JolokiaMvcEndpoint.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2014 the original author or authors.
2+
* Copyright 2013-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -42,6 +42,7 @@
4242
* {@link MvcEndpoint} to expose Jolokia.
4343
*
4444
* @author Christian Dupuis
45+
* @author Andy Wilkinson
4546
*/
4647
@ConfigurationProperties(prefix = "endpoints.jolokia", ignoreUnknownFields = false)
4748
public class JolokiaMvcEndpoint implements MvcEndpoint, InitializingBean,
@@ -51,7 +52,7 @@ public class JolokiaMvcEndpoint implements MvcEndpoint, InitializingBean,
5152
@Pattern(regexp = "/[^/]*", message = "Path must start with /")
5253
private String path;
5354

54-
private boolean sensitive;
55+
private boolean sensitive = true;
5556

5657
private boolean enabled = true;
5758

spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/ManagementSecurityAutoConfigurationTests.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2014 the original author or authors.
2+
* Copyright 2012-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -41,14 +41,18 @@
4141
import org.springframework.util.StringUtils;
4242
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
4343

44+
import static org.hamcrest.Matchers.greaterThan;
45+
import static org.hamcrest.Matchers.hasSize;
4446
import static org.junit.Assert.assertEquals;
4547
import static org.junit.Assert.assertNotNull;
48+
import static org.junit.Assert.assertThat;
4649
import static org.junit.Assert.assertTrue;
4750

4851
/**
4952
* Tests for {@link ManagementSecurityAutoConfiguration}.
5053
*
5154
* @author Dave Syer
55+
* @author Andy Wilkinson
5256
*/
5357
public class ManagementSecurityAutoConfigurationTests {
5458

@@ -71,11 +75,16 @@ public void testWebConfiguration() throws Exception {
7175
EndpointAutoConfiguration.class, EndpointWebMvcAutoConfiguration.class,
7276
ManagementServerPropertiesAutoConfiguration.class,
7377
PropertyPlaceholderAutoConfiguration.class);
78+
EnvironmentTestUtils.addEnvironment(this.context, "security.basic.enabled:false");
7479
this.context.refresh();
7580
assertNotNull(this.context.getBean(AuthenticationManagerBuilder.class));
81+
FilterChainProxy filterChainProxy = this.context.getBean(FilterChainProxy.class);
7682
// 6 for static resources, one for management endpoints and one for the rest
77-
assertEquals(8, this.context.getBean(FilterChainProxy.class).getFilterChains()
78-
.size());
83+
assertThat(filterChainProxy.getFilterChains(), hasSize(8));
84+
assertThat(filterChainProxy.getFilters("/beans"), hasSize(greaterThan(0)));
85+
assertThat(filterChainProxy.getFilters("/beans/"), hasSize(greaterThan(0)));
86+
assertThat(filterChainProxy.getFilters("/beans.foo"), hasSize(greaterThan(0)));
87+
assertThat(filterChainProxy.getFilters("/beans/foo/bar"), hasSize(greaterThan(0)));
7988
}
8089

8190
@Test

0 commit comments

Comments
 (0)