Permalink
Browse files

Make sure that rails recognized the full notation of IPv6 loopback ad…

…dress, and recognize 127.0.0.0/8 in IPv4

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
1 parent a7edddf commit c6ad64394b927a64a221a89087ec1ea7d666ed55 @sikachu sikachu committed with josevalim Jun 6, 2010
@@ -6,7 +6,7 @@ module ActionDispatch
# This middleware rescues any exception returned by the application and renders
# nice exception pages if it's being rescued locally.
class ShowExceptions
- LOCALHOST = ['127.0.0.1', '::1'].freeze
+ LOCALHOST = [/^127\.0\.0\.\d{1,3}$/, /^::1$/, /^0:0:0:0:0:0:0:1(%.*)?$/].freeze
RESCUES_TEMPLATE_PATH = File.join(File.dirname(__FILE__), 'templates')
@@ -114,7 +114,7 @@ def rescue_action_in_public(exception)
# True if the request came from localhost, 127.0.0.1.
def local_request?(request)
- LOCALHOST.any?{ |local_ip| request.remote_addr == local_ip && request.remote_ip == local_ip }
+ LOCALHOST.any?{ |local_ip| request.remote_addr =~ local_ip && request.remote_ip =~ local_ip }
end
def status_code(exception)
@@ -53,7 +53,7 @@ class ShowExceptionsTest < ActionController::IntegrationTest
test "rescue locally from a local request" do
@app = ProductionApp
- ['127.0.0.1', '::1'].each do |ip_address|
+ ['127.0.0.1', '127.0.0.127', '::1', '0:0:0:0:0:0:0:1', '0:0:0:0:0:0:0:1%0'].each do |ip_address|
self.remote_addr = ip_address
get "/", {}, {'action_dispatch.show_exceptions' => true}

0 comments on commit c6ad643

Please sign in to comment.