Caught a bug on the exception path of redirect_back_or_default. #1916
This commit is contained in:
1 parent
099e87fda8
commit
b21430a7f2
2 files changed
+9
-1
No files matched your search
@@ -132,12 +132,13 @@ class RatesController < ApplicationController
|
|||||||
if !back_url.blank?
|
if !back_url.blank?
|
||||||
begin
|
begin
|
||||||
uri = URI.parse(back_url)
|
uri = URI.parse(back_url)
|
||||||
if uri.path.match(whitelist)
|
if uri.path && uri.path.match(whitelist)
|
||||||
super
|
super
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
rescue URI::InvalidURIError
|
rescue URI::InvalidURIError
|
||||||
# redirect to default
|
# redirect to default
|
||||||
|
logger.debug("Invalid URI sent to redirect_back_or_default: " + params[:back_url].inspect)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
redirect_to default
|
redirect_to default
|
||||||
|
|||||||
@@ -474,5 +474,12 @@ describe RatesController, "as an administrator" do
|
|||||||
controller.params = { :back_url => '/back' }
|
controller.params = { :back_url => '/back' }
|
||||||
controller.send(:redirect_back_or_default, @default_url)
|
controller.send(:redirect_back_or_default, @default_url)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should not allow redirecting to an invalid uri" do
|
||||||
|
controller.should_receive(:redirect_to).with(@default_url).and_return(true)
|
||||||
|
controller.params = { :back_url => 'http://' }
|
||||||
|
controller.send(:redirect_back_or_default, @default_url)
|
||||||
|
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Reference in new issue
Block a user