Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 370842 - ProxyServlet should pass :port part of Host header along in the X-Forwarded-Port header
Summary: ProxyServlet should pass :port part of Host header along in the X-Forwarded-...
Status: CLOSED FIXED
Alias: None
Product: Jetty
Classification: RT
Component: server (show other bugs)
Version: unspecified   Edit
Hardware: Macintosh Mac OS X - Carbon (unsup.)
: P3 normal (vote)
Target Milestone: 7.5.x   Edit
Assignee: Thomas Becker CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-02-07 10:27 EST by Eirik Bjørsnøs CLA
Modified: 2012-04-02 09:51 EDT (History)
3 users (show)

See Also:


Attachments
proposed patch (6.39 KB, patch)
2012-02-23 09:08 EST, Thomas Becker CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Eirik Bjørsnøs CLA 2012-02-07 10:27:36 EST
Build Identifier: 

The current ProxyServlet sets X-Forwarded-Host like this:

exchange.addRequestHeader("X-Forwarded-Host",request.getServerName());

This strips out the :port part of :servername:port.

Specifically, if the client request contains "Host: example.com:8080", the X-Forwarded-Host will be set to "servername", not "servername:8080".

This makes the proxied service create wrong redirect urls since it thinks it's responding on port 80.

My local fix was to override customizeExchange like this:

@Override
protected void customizeExchange(HttpExchange exchange, HttpServletRequest request) {
     exchange.setRequestHeader("X-Forwarded-Host", request.getHeader("Host"));
}


But I expect the default behavior should be updated to pass the Host header along unmodified. 

Or is there some security or protocol issue I'm ignoring?

Reproducible: Always

Steps to Reproduce:
1. Add a ProxyServlet to a webapp using redirects
2. Access the proxy url with a custom port (8080)
3. Observe a redirect with an unspecified port
Comment 1 Thomas Becker CLA 2012-02-23 09:08:44 EST
Created attachment 211485 [details]
proposed patch

I've added a unit test for this and changed the line setting the header to:

exchange.addRequestHeader("X-Forwarded-Host",request.getHeader("Host"));

That's the same behaviour as apache httpd's mod_proxy.
Comment 2 Thomas Becker CLA 2012-03-01 09:20:05 EST
Change pushed to gerrit:

https://git.eclipse.org/r/#/c/5201/