]> git.openstreetmap.org Git - rails.git/blobdiff - app/controllers/application_controller.rb
Reject referers that do not include an absolute path
[rails.git] / app / controllers / application_controller.rb
index 9f2d79eaa7bf5845b4c1cb78332e11b9798170b9..d571535d356ef4db7646df3b618c816b2b6f4574 100644 (file)
@@ -1,4 +1,6 @@
 class ApplicationController < ActionController::Base
+  require "timeout"
+
   include SessionPersistence
 
   protect_from_forgery :with => :exception
@@ -57,7 +59,7 @@ class ApplicationController < ActionController::Base
   def require_user
     unless current_user
       if request.get?
-        redirect_to :controller => "users", :action => "login", :referer => request.fullpath
+        redirect_to login_path(:referer => request.fullpath)
       else
         head :forbidden
       end
@@ -229,7 +231,7 @@ class ApplicationController < ActionController::Base
   ##
   # wrap an api call in a timeout
   def api_call_timeout(&block)
-    OSM::Timer.timeout(Settings.api_timeout, Timeout::Error, &block)
+    Timeout.timeout(Settings.api_timeout, Timeout::Error, &block)
   rescue Timeout::Error
     raise OSM::APITimeoutError
   end
@@ -237,7 +239,7 @@ class ApplicationController < ActionController::Base
   ##
   # wrap a web page in a timeout
   def web_timeout(&block)
-    OSM::Timer.timeout(Settings.web_timeout, Timeout::Error, &block)
+    Timeout.timeout(Settings.web_timeout, Timeout::Error, &block)
   rescue ActionView::Template::Error => e
     e = e.cause
 
@@ -354,7 +356,7 @@ class ApplicationController < ActionController::Base
       end
     elsif request.get?
       respond_to do |format|
-        format.html { redirect_to :controller => "users", :action => "login", :referer => request.fullpath }
+        format.html { redirect_to login_path(:referer => request.fullpath) }
         format.any { head :forbidden }
       end
     else
@@ -391,6 +393,8 @@ class ApplicationController < ActionController::Base
       referer = nil
     end
 
+    referer = nil if referer&.path&.first != "/"
+
     referer.to_s
   end
 end