{"action":"created","issue":{"url":"https://api.github.com/repos/rails/rails/issues/5223","repository_url":"https://api.github.com/repos/rails/rails","labels_url":"https://api.github.com/repos/rails/rails/issues/5223/labels{/name}","comments_url":"https://api.github.com/repos/rails/rails/issues/5223/comments","events_url":"https://api.github.com/repos/rails/rails/issues/5223/events","html_url":"https://github.com/rails/rails/issues/5223","id":3443840,"number":5223,"title":"RemoteIp middleware trusted proxies config does not affect Rack::Request::trusted_proxy?","user":{"login":"courtland","id":12778,"avatar_url":"https://avatars.githubusercontent.com/u/12778?v=3","gravatar_id":"","url":"https://api.github.com/users/courtland","html_url":"https://github.com/courtland","followers_url":"https://api.github.com/users/courtland/followers","following_url":"https://api.github.com/users/courtland/following{/other_user}","gists_url":"https://api.github.com/users/courtland/gists{/gist_id}","starred_url":"https://api.github.com/users/courtland/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/courtland/subscriptions","organizations_url":"https://api.github.com/users/courtland/orgs","repos_url":"https://api.github.com/users/courtland/repos","events_url":"https://api.github.com/users/courtland/events{/privacy}","received_events_url":"https://api.github.com/users/courtland/received_events","type":"User","site_admin":false},"labels":[{"id":107189,"url":"https://api.github.com/repos/rails/rails/labels/actionpack","name":"actionpack","color":"FFF700","default":false},{"id":126910270,"url":"https://api.github.com/repos/rails/rails/labels/With%20reproduction%20steps","name":"With reproduction steps","color":"009800","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":25,"created_at":"2012-02-29T20:43:11Z","updated_at":"2016-11-30T04:13:49Z","closed_at":null,"body":"I have clients that connect to my rails app from a private IP address, where the clients real IP is presented to rails via the X-Forwarded-For header (Thin cluster behind a pound load balancer). By default, rails assumes these private addresses are \"trusted proxies\", which causes Request#remote_ip to return '127.0.0.1'.\n\nThis was somewhat addressed by pull request #2632 by making TRUSTED_PROXIES configurable in the RemoteIp Class.\n\nHowever, Rails::Rack::Logger methods still call Rack::Request#ip which causes the IP address displayed in my logs to be 127.0.0.1.\n\nBased on this change in rack: https://github.com/rack/rack/pull/192\nIt seems that ActionDispatch::Request should override Rack::Request#trusted_proxy? with the same \"trusted proxies\" that are configured for RemoteIp.\n\nAt the moment I have the following in an initializer to fix the problem for me, but it is obviously a really bad hack.\n\n```\nmodule Rack\n  class Request\n    def trusted_proxy?(ip)\n      ip =~ /^127\\.0\\.0\\.1$/\n    end\n  end\nend\n```\n\nDoes anyone have comments or suggestions otherwise? I can attempt a patch if my logic seems sound. Thanks.\n"},"comment":{"url":"https://api.github.com/repos/rails/rails/issues/comments/263778719","html_url":"https://github.com/rails/rails/issues/5223#issuecomment-263778719","issue_url":"https://api.github.com/repos/rails/rails/issues/5223","id":263778719,"user":{"login":"kvokka","id":15954013,"avatar_url":"https://avatars.githubusercontent.com/u/15954013?v=3","gravatar_id":"","url":"https://api.github.com/users/kvokka","html_url":"https://github.com/kvokka","followers_url":"https://api.github.com/users/kvokka/followers","following_url":"https://api.github.com/users/kvokka/following{/other_user}","gists_url":"https://api.github.com/users/kvokka/gists{/gist_id}","starred_url":"https://api.github.com/users/kvokka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kvokka/subscriptions","organizations_url":"https://api.github.com/users/kvokka/orgs","repos_url":"https://api.github.com/users/kvokka/repos","events_url":"https://api.github.com/users/kvokka/events{/privacy}","received_events_url":"https://api.github.com/users/kvokka/received_events","type":"User","site_admin":false},"created_at":"2016-11-30T04:13:49Z","updated_at":"2016-11-30T04:13:49Z","body":"This bug is still present in Rails 5.0.0.1. Syntax changes a little, so, I had to add in \r\n    # config/application.rb\r\n    config.action_dispatch.trusted_proxies = %w(127.0.0.1 ::1).map { |proxy| IPAddr.new(proxy) }\r\n    config.middleware.insert_before(Rails::Rack::Logger,\r\n                                    ActionDispatch::RemoteIp,\r\n                                    true,\r\n                                    config.action_dispatch.trusted_proxies)\r\n\r\n   # config/initializers/action_dispatch.rb\r\n    module TrustedProxyMonkeyPatch\r\n      def ip\r\n        @ip ||= (get_header(\"action_dispatch.remote_ip\") || super).to_s\r\n      end\r\n    end\r\n    ActionDispatch::Request.send :include, TrustedProxyMonkeyPatch\r\n"}}
{"actor":{"display_login":"kvokka"}}