]> git.openstreetmap.org Git - rails.git/blobdiff - app/controllers/application_controller.rb
Merge remote-tracking branch 'upstream/pull/3484'
[rails.git] / app / controllers / application_controller.rb
index 517b11e140818818dd7ab16b7219a39f04337720..bb32e7e6e5cbbe25da6787efc37dce39266e8c8d 100644 (file)
@@ -349,7 +349,7 @@ class ApplicationController < ActionController::Base
     elsif current_user
       set_locale
       respond_to do |format|
-        format.html { redirect_to :controller => "errors", :action => "forbidden" }
+        format.html { redirect_to :controller => "/errors", :action => "forbidden" }
         format.any { report_error t("application.permission_denied"), :forbidden }
       end
     elsif request.get?
@@ -381,19 +381,23 @@ class ApplicationController < ActionController::Base
 
   # clean any referer parameter
   def safe_referer(referer)
-    referer = URI.parse(referer)
+    begin
+      referer = URI.parse(referer)
+
+      if referer.scheme == "http" || referer.scheme == "https"
+        referer.scheme = nil
+        referer.host = nil
+        referer.port = nil
+      elsif referer.scheme || referer.host || referer.port
+        referer = nil
+      end
 
-    if referer.scheme == "http" || referer.scheme == "https"
-      referer.scheme = nil
-      referer.host = nil
-      referer.port = nil
-    elsif referer.scheme || referer.host || referer.port
+      referer = nil if referer&.path&.first != "/"
+    rescue URI::InvalidURIError
       referer = nil
     end
 
-    referer = nil if referer&.path&.first != "/"
-
-    referer.to_s
+    referer&.to_s
   end
 
   def scope_enabled?(scope)