Skip to content

Loading…

x-forwarded-port not being set correctly... maybe #341

Closed
blahed opened this Issue · 4 comments

4 participants

@blahed

My understanding is that x-forwarded-port should be set to the server port that the request came in on: 80, 443, etc.

If that's the case, it's not happening. req.connection.remotePort is the requesting client's remote port. I didn't see an obvious way to get the server from the request, but it seems easy enough to determine it from the host header/protocol.

Assuming I'm understanding x-forwarded-port correctly, I've got a branch that fixes the issue here:

https://github.com/blahed/node-http-proxy/compare/x-forwarded-port

@hmalphettes

+1
I have used x-forwarded-port with nginx; the expected value of the header is the port of the original request before it was proxied.

Say my node server is running on 3000 and is proxied by node-http-proxy on 3001.
I would like to know when crafting URLs for the original client that the public port is 3001.
At the moment node-http-proxy would give me something like 62112.

I have tested @blahed's patch and it works for me.

@blahed blahed added a commit to blahed/node-http-proxy that referenced this issue
@blahed blahed determine x-forwarded-port from host header
`req.remotePort' returns the ephemeral port, which is not useful.
node v0.10.0 added `req.localPort' which returns what we want, but
we want to maintain backwards compatibility. Fixes #341 & #227
3bbb2c8
@fideloper

Hello!

I'm just coming across this now. I was wondering if there was a planned resolution, or something I missed?

Installing node v0.10.23 and node-http-proxy 0.10.3 shows the same behavior for me.

Edit: The caronte branch exhibits this behavior as well.

@yawnt yawnt added a commit that referenced this issue
@yawnt yawnt [fix] fixes #341 97e4600
@yawnt

@fideloper fixed in 97e4600 :)

@yawnt yawnt closed this
@fideloper

Awesome, thanks!

@indexzero indexzero added a commit that referenced this issue
@blahed blahed determine x-forwarded-port from host header
`req.remotePort' returns the ephemeral port, which is not useful.
node v0.10.0 added `req.localPort' which returns what we want, but
we want to maintain backwards compatibility. Fixes #341 & #227
d4e91eb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.