* Update erb_lint to track newer Rubocop versions * Update rubocop-rspec to 2.1 * Fix Rails/WhereEquals and Style/RedundantParentheses * Upgrade rubocop to 1.1.0 * Enable Rubocop 1.1 cops * Upgrade rubocop to 1.2.0 * Enable Rubocop 1.2 cops * Upgrade rubocop to 1.3.0 * Enable Rubocop 1.3 cops * Enable Rubocop 1.4 cops * Enable Rubocop 1.5 cops * Upgrade rubocop to 1.6.x * Restore previous .reject * Fork the PR to make sure we don't inject unwanted code accidentally
38 lines
1.4 KiB
Ruby
38 lines
1.4 KiB
Ruby
module ValidRequest
|
|
extend ActiveSupport::Concern
|
|
|
|
def valid_request_origin?
|
|
# This manually does what it was supposed to do on its own.
|
|
# We were getting this issue:
|
|
# HTTP Origin header (https://dev.to) didn't match request.base_url (http://dev.to)
|
|
# Not sure why, but once we work it out, we can delete this method.
|
|
# We are at least secure for now.
|
|
return if Rails.env.test?
|
|
|
|
if request.referer.present?
|
|
request.referer.start_with?(URL.url)
|
|
else
|
|
null_origin = request.origin == "null"
|
|
raise ::ActionController::InvalidAuthenticityToken, ::ApplicationController::NULL_ORIGIN_MESSAGE if null_origin
|
|
|
|
request.origin.nil? || request.origin.gsub("https", "http") == request.base_url.gsub("https", "http")
|
|
end
|
|
end
|
|
|
|
def _compute_redirect_to_location(request, options) #:nodoc:
|
|
case options
|
|
# Yet another monkeypatch required to send proper protocol out.
|
|
# In this case we make sure the redirect ends in the app protocol.
|
|
# This is the same as the base Rails method except URL.protocol
|
|
# is used instead of request.protocol.
|
|
when %r{\A([a-z][a-z\d\-+.]*:|//).*}i
|
|
options
|
|
when String
|
|
"#{URL.protocol || request.protocol}#{request.host_with_port}#{options}"
|
|
when Proc
|
|
_compute_redirect_to_location request, instance_eval(&options)
|
|
else
|
|
url_for(options)
|
|
end.delete("\0\r\n")
|
|
end
|
|
end
|