]> git.openstreetmap.org Git - rails.git/blobdiff - app/controllers/application_controller.rb
Update to rails 6.1.4.2
[rails.git] / app / controllers / application_controller.rb
index 517b11e140818818dd7ab16b7219a39f04337720..07b23ce21c814561c8266cff403a46874bb4cbb8 100644 (file)
@@ -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)