Skip to content

Commit 147368e

Browse files
committed
Proactively reject URLs without target address
Issue: SPR-15782
1 parent cbe5a67 commit 147368e

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpConnector.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ public ReactorClientHttpConnector(Consumer<? super HttpClientOptions.Builder> cl
6868
public Mono<ClientHttpResponse> connect(HttpMethod method, URI uri,
6969
Function<? super ClientHttpRequest, Mono<Void>> requestCallback) {
7070

71+
if (!uri.isAbsolute()) {
72+
return Mono.error(new IllegalArgumentException("URI is not absolute: " + uri));
73+
}
74+
7175
return this.httpClient
7276
.request(adaptHttpMethod(method),
7377
uri.toString(),

spring-webflux/src/test/java/org/springframework/web/reactive/function/client/WebClientIntegrationTests.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,16 @@ public void exchangeNoContent() throws Exception {
568568
}).verifyComplete();
569569
}
570570

571+
@Test // SPR-15782
572+
public void absoluteUri() throws Exception {
573+
String uri = "/api/v4/groups/1";
574+
Mono<ClientResponse> responseMono = WebClient.builder().build().get().uri(uri).exchange();
575+
576+
StepVerifier.create(responseMono)
577+
.expectErrorMessage("URI is not absolute: " + uri)
578+
.verify(Duration.ofSeconds(5));
579+
}
580+
571581

572582
@SuppressWarnings("serial")
573583
private static class MyException extends RuntimeException {

0 commit comments

Comments
 (0)