Skip to content

Commit

Permalink
see #249 Fix X-Forwarded-For to use remote host information
Browse files Browse the repository at this point in the history
The "X-Forwarded-For" request header is about the remote host
information, not the server host information.

Follow-up to #249, reviewed in #373
  • Loading branch information
bclozel authored and simonbasle committed Jun 13, 2018
1 parent 91f45dc commit a9fba51
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/main/java/reactor/netty/http/server/ConnectionInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ static ConnectionInfo parseXForwardedInfo(HttpRequest request, SocketChannel cha
InetSocketAddress remoteAddress = channel.remoteAddress();
String scheme = channel.pipeline().get(SslHandler.class) != null ? "https" : "http";
if (request.headers().contains(XFORWARDED_IP_HEADER)) {
String hostValue = request.headers().get(XFORWARDED_IP_HEADER).split(",")[0];
hostAddress = parseAddress(hostValue, hostAddress.getPort());
String remoteIpValue = request.headers().get(XFORWARDED_IP_HEADER).split(",")[0];
remoteAddress = parseAddress(remoteIpValue, remoteAddress.getPort());
}
else if(request.headers().contains(XFORWARDED_HOST_HEADER)) {
if(request.headers().contains(XFORWARDED_PORT_HEADER)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ public void xForwardedFor() {
clientRequestHeaders -> clientRequestHeaders.add("X-Forwarded-For",
"[1abc:2abc:3abc::5ABC:6abc]:8080, 192.168.0.1"),
serverRequest -> {
Assertions.assertThat(serverRequest.hostAddress().getHostString()).isEqualTo("1abc:2abc:3abc:0:0:0:5abc:6abc");
Assertions.assertThat(serverRequest.hostAddress().getPort()).isEqualTo(8080);
Assertions.assertThat(serverRequest.remoteAddress().getHostString()).isEqualTo("1abc:2abc:3abc:0:0:0:5abc:6abc");
Assertions.assertThat(serverRequest.remoteAddress().getPort()).isEqualTo(8080);
});
}

Expand Down

0 comments on commit a9fba51

Please sign in to comment.