Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

X-Forwarded-For ignored when "trusted" #1010

Closed
lighthouse-import opened this Issue · 2 comments

3 participants

@lighthouse-import

Imported from Lighthouse. Original ticket at: http://rails.lighthouseapp.com/projects/8994/tickets/6687
Created by jaswope - 2011-04-08 14:28:54 UTC

ActionDispatch:RemoteIp ignores X-Forwarded-For if all of the IPs it contains are considered trusted proxies. This list includes localhost and all private addresses.

This impacts applications that are hosted behind a reverse proxy (proxying to localhost) and accessed from a private IP, such as intranet applications. Aside from making the remote ip detection incorrect, this causes problems with ActionDispatch::Request.local?, causing it to incorrectly return true, which in turn causes default configurations of Rails apps to show stack traces when they shouldn't.

The offending line appears to be here: https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/middleware/remote_ip.rb#L34

Perhaps it should fall back to the last ip in the forwarded for chain instead:

return forwarded_ips.reject { |ip| ip =~ @trusted_proxies }.last || forwarded_ips.last
@adamcrown

I'm not sure why this was closed. It looks like it was automatically closed after the move from Lighthouse. But I'm still experiencing this issue.

It seems to me that it should simply be the first IP in the forwarded_ips array that should be grabbed. I don't see why all of the trusted ranges should be rejected since the client could be coming from one of the trusted IP ranges.

return forwarded_ips.first || @env["REMOTE_ADDR"]
@tilsammans

As far as I know, is now configurable using config.action_dispatch.trusted_proxies=.

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.