]> source.dussan.org Git - redmine.git/commitdiff
Do not use escaped back_url param (#11691).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 26 Aug 2012 10:40:09 +0000 (10:40 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 26 Aug 2012 10:40:09 +0000 (10:40 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10239 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/application_controller.rb
app/helpers/application_helper.rb
test/functional/account_controller_test.rb

index d6efa412423030ad5f8135a3c8d2a1523b896d00..aacb8e52356916ae2792bda5f0699668f8344c51 100644 (file)
@@ -296,12 +296,16 @@ class ApplicationController < ActionController::Base
   end
 
   def back_url
-    params[:back_url] || request.env['HTTP_REFERER']
+    url = params[:back_url]
+    if url.nil? && referer = request.env['HTTP_REFERER']
+      url = CGI.unescape(referer.to_s)
+    end
+    url
   end
 
   def redirect_back_or_default(default)
-    back_url = CGI.unescape(params[:back_url].to_s)
-    if !back_url.blank?
+    back_url = params[:back_url].to_s
+    if back_url.present?
       begin
         uri = URI.parse(back_url)
         # do not redirect user to another host or to the login or register page
@@ -310,6 +314,7 @@ class ApplicationController < ActionController::Base
           return
         end
       rescue URI::InvalidURIError
+        logger.warn("Could not redirect to invalid URL #{back_url}")
         # redirect to default
       end
     end
index cfa9cb5ab0c428b19256def0af5bc3ec60a7e845..2706cef78f158b091a9a48e8554dc1046bbfddb2 100644 (file)
@@ -1027,10 +1027,17 @@ module ApplicationHelper
     content_tag(:a, name, {:href => '#', :onclick => "#{function}; return false;"}.merge(html_options))
   end
 
+  def back_url
+    url = params[:back_url]
+    if url.nil? && referer = request.env['HTTP_REFERER']
+      url = CGI.unescape(referer.to_s)
+    end
+    url
+  end
+
   def back_url_hidden_field_tag
-    back_url = params[:back_url] || request.env['HTTP_REFERER']
-    back_url = CGI.unescape(back_url.to_s)
-    hidden_field_tag('back_url', CGI.escape(back_url), :id => nil) unless back_url.blank?
+    url = back_url
+    hidden_field_tag('back_url', url, :id => nil) unless url.blank?
   end
 
   def check_all_links(form_name)
index f48e4b3a62a9f72c1a8bf5bcca31b0c89957b05f..7b5a449e5b6ff17b3a3d7d81f60cbcf45aaae278 100644 (file)
@@ -33,12 +33,12 @@ class AccountControllerTest < ActionController::TestCase
 
   def test_login_should_redirect_to_back_url_param
     # request.uri is "test.host" in test environment
-    post :login, :username => 'jsmith', :password => 'jsmith', :back_url => 'http%3A%2F%2Ftest.host%2Fissues%2Fshow%2F1'
+    post :login, :username => 'jsmith', :password => 'jsmith', :back_url => 'http://test.host/issues/show/1'
     assert_redirected_to '/issues/show/1'
   end
 
   def test_login_should_not_redirect_to_another_host
-    post :login, :username => 'jsmith', :password => 'jsmith', :back_url => 'http%3A%2F%2Ftest.foo%2Ffake'
+    post :login, :username => 'jsmith', :password => 'jsmith', :back_url => 'http://test.foo/fake'
     assert_redirected_to '/my/page'
   end