Skip to content

Commit 565e625

Browse files
committed
Fix #31010: include port in X-Forwarded-Host header
1 parent fa2ba1c commit 565e625

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

src/main/java/eu/openanalytics/containerproxy/util/ProxyMappingManager.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import io.undertow.util.StatusCodes;
4545
import org.springframework.context.event.ContextClosedEvent;
4646
import org.springframework.context.event.EventListener;
47+
import org.springframework.security.web.header.Header;
4748
import org.springframework.stereotype.Component;
4849

4950
import javax.inject.Inject;
@@ -171,6 +172,13 @@ public void dispatchAsync(String proxyId, String mapping, HttpServletRequest req
171172
if (exchangeCustomizer != null) {
172173
exchangeCustomizer.accept(exchange);
173174
}
175+
// see #31010
176+
// by default Undertow adds a Headers.X_FORWARDED_HOST header using exchange.getHost(), this never includes the server port
177+
// however, the original Host header includes the port if using a non-standard port (i.e. not 80 and 443)
178+
// this causes problems for applications comparing the Host and/or Origin header
179+
// therefore we set the header here using exchange.getHostAndPort(), which only includes the port if non-standard port such that it matches the Host header
180+
// note: if we set the header here, undertow does not override it
181+
exchange.getRequestHeaders().put(Headers.X_FORWARDED_HOST, exchange.getHostAndPort());
174182
exchange.addDefaultResponseListener(defaultResponseListener);
175183
request.startAsync();
176184
request.getRequestDispatcher(targetPath).forward(request, response);

0 commit comments

Comments
 (0)