Validate that we actually have a hostname when using a load balanced URI. Fixes #779

This commit is contained in:
Ryan Baxter
2019-01-17 10:10:50 -05:00
parent dfc52c7ad1
commit 242fc34305
2 changed files with 14 additions and 0 deletions

View File

@@ -68,6 +68,12 @@ public class RouteToRequestUrlFilter implements GlobalFilter, Ordered {
routeUri = URI.create(routeUri.getSchemeSpecificPart());
}
if("lb".equalsIgnoreCase(routeUri.getScheme()) && routeUri.getHost() == null) {
//Load balanced URIs should always have a host. If the host is null it is most
//likely because the host name was invalid (for example included an underscore)
throw new IllegalStateException("Invalid host: " + routeUri.toString());
}
URI mergedUrl = UriComponentsBuilder.fromUri(uri)
// .uri(routeUri)
.scheme(routeUri.getScheme())

View File

@@ -66,6 +66,14 @@ public class RouteToRequestUrlFilterTests {
assertThat(uri).hasScheme("lb").hasHost("myhost");
}
@Test(expected = IllegalStateException.class)
public void invalidHost() {
MockServerHttpRequest request = MockServerHttpRequest
.get("http://localhost/getb")
.build();
testFilter(request, "lb://my_host");
}
@Test
public void happyPathLbPlusScheme() {
MockServerHttpRequest request = MockServerHttpRequest