1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/actionpack/test
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
..
abstract Only compute :only and :except callback conditions once 2020-04-06 11:51:30 +02:00
assertions Use frozen string literal in actionpack/ 2017-07-29 14:02:40 +03:00
controller Make NameError#missing_name work even for real Ruby NameError 2020-05-08 17:08:38 +02:00
dispatch Don’t ignore X-Forwarded-For IPs with ports attached 2020-05-09 22:23:34 -04:00
fixtures Change the empty block style to have space inside of the block 2018-09-25 13:19:35 -04:00
journey Remove unused journey code 2020-04-25 00:40:37 +09:00
lib Document view components support (#38656) 2020-03-13 23:52:49 +01:00
routing Use frozen string literal in actionpack/ 2017-07-29 14:02:40 +03:00
abstract_unit.rb Fix typo 2020-05-03 05:43:01 +09:00