Skip to content

Commit 25f31a6

Browse files
authored
Merge pull request #53153 from geoand/#53150
Ensure that invalid forwarded headers results in HTTP 400
2 parents c9f7c16 + ef5d12e commit 25f31a6

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package io.quarkus.vertx.http.proxy;
2+
3+
import static io.restassured.RestAssured.given;
4+
import static org.hamcrest.Matchers.equalTo;
5+
6+
import jakarta.enterprise.context.ApplicationScoped;
7+
import jakarta.enterprise.event.Observes;
8+
9+
import org.junit.jupiter.api.Test;
10+
import org.junit.jupiter.api.extension.RegisterExtension;
11+
12+
import io.quarkus.test.QuarkusExtensionTest;
13+
import io.vertx.ext.web.Router;
14+
15+
public class InvalidProxyHostTest {
16+
17+
@RegisterExtension
18+
static final QuarkusExtensionTest config = new QuarkusExtensionTest()
19+
.withApplicationRoot((jar) -> jar
20+
.addClasses(RouteInitializer.class))
21+
.overrideRuntimeConfigKey("quarkus.http.proxy.proxy-address-forwarding", "true");
22+
23+
@Test
24+
public void test() {
25+
given()
26+
.header("X-Forwarded-For", ":abcd")
27+
.get("/path")
28+
.then()
29+
.statusCode(400);
30+
31+
given()
32+
.header("X-Forwarded-For", "1.2.3.4")
33+
.get("/path")
34+
.then()
35+
.body(equalTo("hello"));
36+
}
37+
38+
@ApplicationScoped
39+
public static class RouteInitializer {
40+
41+
public void register(@Observes Router router) {
42+
router.route("/path").handler(rc -> rc.response().end("hello"));
43+
}
44+
45+
}
46+
}

extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/options/HttpServerCommonHandlers.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,19 @@ public static Handler<HttpServerRequest> applyProxy(ProxyConfig proxyConfig, Han
9898
if (proxyCheckBuilder == null) {
9999
// no proxy check => we do not restrict who can send `X-Forwarded` or `X-Forwarded-*` headers
100100
final TrustedProxyCheck allowAllProxyCheck = allowAll();
101-
return new Handler<HttpServerRequest>() {
101+
return new Handler<>() {
102102
@Override
103103
public void handle(HttpServerRequest event) {
104-
root.handle(new ForwardedServerRequestWrapper(event, forwardingProxyOptions, allowAllProxyCheck));
104+
ForwardedServerRequestWrapper wrapper;
105+
try {
106+
wrapper = new ForwardedServerRequestWrapper(event, forwardingProxyOptions, allowAllProxyCheck);
107+
@SuppressWarnings("unused")
108+
var unused = wrapper.authority();
109+
} catch (IllegalArgumentException e) {
110+
event.response().setStatusCode(400).end();
111+
return;
112+
}
113+
root.handle(wrapper);
105114
}
106115
};
107116
} else {

0 commit comments

Comments
 (0)