1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/actionpack/lib/action_dispatch
Duncan Brown fbf1d82e0d
Don’t ignore X-Forwarded-For IPs with ports attached
Rack decided to tolerate proxies which choose to attach ports to
X-Forwarded-For IPs by stripping the port:
https://github.com/rack/rack/pull/1251. Attaching a port is rare in the
wild but some proxies (notably Microsoft Azure's App Service) do it.

Without this patch, remote_ip will ignore X-Forwarded-For IPs with ports
attached and the return value is less likely to be useful.

Rails should do the same thing. The stripping logic is already available
in Rack::Request::Helpers, so change the X-Forwarded-For retrieval
method from ActionDispatch::Request#x_forwarded_for (which returns the
raw header) to #forwarded_for, which returns a stripped array of IP
addresses, or nil. There may be other benefits hiding in Rack's
implementation.

We can't call ips_from with an array (and legislating for that inside
ips_from doesn't appeal), so refactor out the bit we need to apply in
both cases (verifying the IP is acceptable to IPAddr and that it's not a
range) to a separate method called #sanitize_ips which reduces an array of
maybe-ips to an array of acceptable ones.
2020-05-09 22:23:34 -04:00
..
http Dogfooding "active_support/core_ext/symbol/starts_ends_with" 2020-05-06 14:19:25 +09:00
journey Merge pull request #39034 from vinistock/build_simulator_memos_in_one_loop 2020-04-24 20:08:12 +02:00
middleware Don’t ignore X-Forwarded-For IPs with ports attached 2020-05-09 22:23:34 -04:00
request Enable HashTransformKeys and HashTransformValues cops 2020-02-20 22:37:32 +00:00
routing Dogfooding "active_support/core_ext/symbol/starts_ends_with" 2020-05-06 14:19:25 +09:00
system_testing Load selenium/webdriver only if needed 2020-05-07 15:53:32 +03:00
testing Remove unused require "active_support/core_ext/kernel/singleton_class" 2020-05-10 03:20:02 +09:00
journey.rb Remove unused journey code 2020-04-25 00:40:37 +09:00
railtie.rb Heed config.force_ssl when building URL 2020-04-05 18:19:31 -05:00
routing.rb Fix code examples' indentation in ActionDispatch::Routing [ci skip] 2019-02-26 14:04:08 -05:00
system_test_case.rb Load selenium/webdriver only if needed 2020-05-07 15:53:32 +03:00