X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/f4d1d97848306e71b6525c58f2e5691b8aa686b7..b0288b83bb437bbfc0deb325cca142066dc9848b:/app/controllers/application_controller.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 517b11e14..07b23ce21 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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)