Skip to content

Commit 308f1e8

Browse files
committed
Do not serve index.html for logfile/heapdump
fixes #1338
1 parent d286e83 commit 308f1e8

File tree

8 files changed

+225
-210
lines changed

8 files changed

+225
-210
lines changed

spring-boot-admin-server-ui/package-lock.json

Lines changed: 171 additions & 187 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spring-boot-admin-server-ui/package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
"@fortawesome/vue-fontawesome": "^0.1.9",
1717
"ansi_up": "^4.0.4",
1818
"autolinker": "^3.11.1",
19-
"axios": "^0.19.0",
19+
"axios": "^0.19.1",
2020
"bulma": "^0.8.0",
2121
"bulma-badge": "^3.0.1",
22-
"core-js": "^3.6.0",
22+
"core-js": "^3.6.3",
2323
"d3-array": "^2.4.0",
2424
"d3-axis": "^1.0.12",
2525
"d3-brush": "^1.1.5",
@@ -35,29 +35,29 @@
3535
"popper.js": "^1.16.0",
3636
"pretty-bytes": "^5.3.0",
3737
"resize-observer-polyfill": "^1.5.1",
38-
"rxjs": "^6.5.3",
38+
"rxjs": "^6.5.4",
3939
"vue": "^2.6.11",
4040
"vue-clickaway2": "^2.3.1",
4141
"vue-i18n": "^8.15.3",
4242
"vue-infinite-loading": "^2.4.4",
4343
"vue-router": "^3.1.2"
4444
},
4545
"devDependencies": {
46-
"@vue/cli-plugin-babel": "^4.1.1",
47-
"@vue/cli-plugin-eslint": "^4.1.1",
48-
"@vue/cli-plugin-unit-jest": "^4.1.1",
49-
"@vue/cli-service": "^4.1.1",
46+
"@vue/cli-plugin-babel": "^4.1.2",
47+
"@vue/cli-plugin-eslint": "^4.1.2",
48+
"@vue/cli-plugin-unit-jest": "^4.1.2",
49+
"@vue/cli-service": "^4.1.2",
5050
"@vue/eslint-config-standard": "^4.0.0",
5151
"@vue/test-utils": "^1.0.0-beta.30",
5252
"babel-core": "7.0.0-bridge.0",
5353
"babel-eslint": "^10.0.3",
5454
"babel-jest": "^24.9.0",
5555
"eslint": "^6.8.0",
56-
"eslint-plugin-vue": "^6.0.1",
56+
"eslint-plugin-vue": "^6.1.2",
5757
"html-loader": "^0.5.5",
5858
"jest": "^24.9.0",
5959
"node-sass": "^4.13.0",
60-
"sass-loader": "^8.0.0",
60+
"sass-loader": "^8.0.1",
6161
"vue-template-compiler": "^2.6.11",
6262
"webpack-bundle-analyzer": "^3.6.0"
6363
},

spring-boot-admin-server-ui/src/main/java/de/codecentric/boot/admin/server/ui/config/AdminServerUiAutoConfiguration.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ public class AdminServerUiAutoConfiguration {
6060
private static final List<String> DEFAULT_UI_ROUTES = asList("/about/**", "/applications/**", "/instances/**",
6161
"/journal/**", "/wallboard/**", "/external/**");
6262

63+
private static final List<String> DEFAULT_UI_EXCLUDED_ROUTE = asList("/instances/*/actuator/heapdump",
64+
"/instances/*/actuator/logfile");
65+
6366
private final AdminServerUiProperties adminUi;
6467

6568
private final AdminServerProperties adminServer;
@@ -152,7 +155,8 @@ public de.codecentric.boot.admin.server.ui.web.reactive.HomepageForwardingFilter
152155
List<String> routes = Stream.concat(DEFAULT_UI_ROUTES.stream(), extensionRoutes.stream())
153156
.map(this.adminServer::path).collect(Collectors.toList());
154157
String homepage = this.adminServer.path("/");
155-
return new de.codecentric.boot.admin.server.ui.web.reactive.HomepageForwardingFilter(homepage, routes);
158+
return new de.codecentric.boot.admin.server.ui.web.reactive.HomepageForwardingFilter(homepage, routes,
159+
DEFAULT_UI_EXCLUDED_ROUTE);
156160
}
157161

158162
}
@@ -197,7 +201,8 @@ public de.codecentric.boot.admin.server.ui.web.servlet.HomepageForwardingFilter
197201
List<String> routes = Stream.concat(DEFAULT_UI_ROUTES.stream(), extensionRoutes.stream())
198202
.map(this.adminServer::path).collect(Collectors.toList());
199203
String homepage = this.adminServer.path("/");
200-
return new de.codecentric.boot.admin.server.ui.web.servlet.HomepageForwardingFilter(homepage, routes);
204+
return new de.codecentric.boot.admin.server.ui.web.servlet.HomepageForwardingFilter(homepage, routes,
205+
DEFAULT_UI_EXCLUDED_ROUTE);
201206
}
202207

203208
}

spring-boot-admin-server-ui/src/main/java/de/codecentric/boot/admin/server/ui/web/HomepageForwardingMatcher.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,21 @@
2727

2828
public class HomepageForwardingMatcher<T> implements Predicate<T> {
2929

30-
private final List<Pattern> routes;
30+
private final List<Pattern> includeRoutes;
31+
32+
private final List<Pattern> excludeRoutes;
3133

3234
private final Function<T, String> methodAccessor;
3335

3436
private final Function<T, String> pathAccessor;
3537

3638
private final Function<T, List<MediaType>> acceptsAccessor;
3739

38-
public HomepageForwardingMatcher(List<String> routes, Function<T, String> methodAccessor,
39-
Function<T, String> pathAccessor, Function<T, List<MediaType>> acceptsAccessor) {
40-
this.routes = toPatterns(routes);
40+
public HomepageForwardingMatcher(List<String> includeRoutes, List<String> excludeRoutes,
41+
Function<T, String> methodAccessor, Function<T, String> pathAccessor,
42+
Function<T, List<MediaType>> acceptsAccessor) {
43+
this.includeRoutes = toPatterns(includeRoutes);
44+
this.excludeRoutes = toPatterns(excludeRoutes);
4145
this.methodAccessor = methodAccessor;
4246
this.pathAccessor = pathAccessor;
4347
this.acceptsAccessor = acceptsAccessor;
@@ -48,16 +52,18 @@ public boolean test(T request) {
4852
return false;
4953
}
5054

51-
if (this.routes.stream().noneMatch((p) -> p.matcher(this.pathAccessor.apply(request)).matches())) {
55+
String path = this.pathAccessor.apply(request);
56+
if (this.excludeRoutes.stream().anyMatch((p) -> p.matcher(path).matches())
57+
|| this.includeRoutes.stream().noneMatch((p) -> p.matcher(path).matches())) {
5258
return false;
5359
}
5460

5561
return this.acceptsAccessor.apply(request).stream().anyMatch((t) -> t.includes(MediaType.TEXT_HTML));
5662
}
5763

5864
private List<Pattern> toPatterns(List<String> routes) {
59-
return routes.stream().map((r) -> "^" + r.replaceAll("/[*][*]", "(/.*)?") + "$").map(Pattern::compile)
60-
.collect(Collectors.toList());
65+
return routes.stream().map((r) -> "^" + r.replaceAll("/[*][*]", "(/.*)?").replaceAll("/[*]/", "/[^/]+/") + "$")
66+
.map(Pattern::compile).collect(Collectors.toList());
6167
}
6268

6369
}

spring-boot-admin-server-ui/src/main/java/de/codecentric/boot/admin/server/ui/web/reactive/HomepageForwardingFilter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ public class HomepageForwardingFilter implements WebFilter {
3636

3737
private final HomepageForwardingMatcher<ServerHttpRequest> matcher;
3838

39-
public HomepageForwardingFilter(String homepage, List<String> routes) {
39+
public HomepageForwardingFilter(String homepage, List<String> routeIncludes, List<String> routeExcludes) {
4040
this.homepage = homepage;
41-
this.matcher = new HomepageForwardingMatcher<>(routes, ServerHttpRequest::getMethodValue,
41+
this.matcher = new HomepageForwardingMatcher<>(routeIncludes, routeExcludes, ServerHttpRequest::getMethodValue,
4242
(r) -> r.getPath().pathWithinApplication().toString(), (r) -> r.getHeaders().getAccept());
4343
}
4444

spring-boot-admin-server-ui/src/main/java/de/codecentric/boot/admin/server/ui/web/servlet/HomepageForwardingFilter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ public class HomepageForwardingFilter implements Filter {
4949

5050
private final HomepageForwardingMatcher<HttpServletRequest> matcher;
5151

52-
public HomepageForwardingFilter(String homepage, List<String> routes) {
52+
public HomepageForwardingFilter(String homepage, List<String> routes, List<String> excludedRoutes) {
5353
this.homepage = homepage;
5454
UrlPathHelper urlPathHelper = new UrlPathHelper();
55-
this.matcher = new HomepageForwardingMatcher<>(routes, HttpServletRequest::getMethod,
55+
this.matcher = new HomepageForwardingMatcher<>(routes, excludedRoutes, HttpServletRequest::getMethod,
5656
urlPathHelper::getPathWithinApplication,
5757
(r) -> MediaType.parseMediaTypes(r.getHeader(HttpHeaders.ACCEPT)));
5858
}

spring-boot-admin-server-ui/src/test/java/de/codecentric/boot/admin/server/ui/AbstractAdminUiApplicationTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package de.codecentric.boot.admin.server.ui;
1818

1919
import org.junit.Test;
20+
import org.springframework.http.HttpStatus;
2021
import org.springframework.http.MediaType;
2122
import org.springframework.test.web.reactive.server.WebTestClient;
2223

@@ -44,6 +45,17 @@ public void should_return_index() {
4445
//@formatter:on
4546
}
4647

48+
@Test
49+
public void should_not_return_index_for_logfile() {
50+
//@formatter:off
51+
this.webClient.get()
52+
.uri("/instances/a973ff14be49/actuator/logfile")
53+
.accept(MediaType.TEXT_HTML, MediaType.ALL)
54+
.exchange()
55+
.expectStatus().isEqualTo(HttpStatus.SERVICE_UNAVAILABLE);
56+
//@formatter:on
57+
}
58+
4759
@Test
4860
public void should_return_api() {
4961
//@formatter:off

spring-boot-admin-server-ui/src/test/java/de/codecentric/boot/admin/server/ui/web/HomepageForwardingMatcherTest.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
public class HomepageForwardingMatcherTest {
2929

3030
private final HomepageForwardingMatcher<MockRequest> matcher = new HomepageForwardingMatcher<>(
31-
singletonList("/viewRoute/**"), MockRequest::getMethod, MockRequest::getPath, MockRequest::getAccepts);
31+
singletonList("/viewRoute/**"), singletonList("/viewRoute/*/exclude"), MockRequest::getMethod,
32+
MockRequest::getPath, MockRequest::getAccepts);
3233

3334
@Test
3435
public void should_return_false_when_method_is_not_get() {
@@ -47,6 +48,13 @@ public void should_return_false_when_accepts_does_not_match() {
4748
.isFalse();
4849
}
4950

51+
@Test
52+
public void should_return_false_when_path_is_excluded() {
53+
assertThat(this.matcher
54+
.test(new MockRequest("GET", "/viewRoute/12345/exclude", singletonList(MediaType.TEXT_HTML))))
55+
.isFalse();
56+
}
57+
5058
@Test
5159
public void should_return_true() {
5260
assertThat(this.matcher

0 commit comments

Comments
 (0)