Rails is stubborn because he believes that all GET requests should be idempotent. Does this mean that Rails, of course, does not check authentication tokens for GET requests, even verified_queries? gives each get a pass.
def verified_request? !protect_against_forgery? || request.method == :get || !verifiable_request_format? || form_authenticity_token == params[request_forgery_protection_token] end
So we have to write our own logic. We can use the form_authenticity token. All this creates a random string and caches it in the session:
def form_authenticity_token session[:_csrf_token] ||= ActiveSupport::SecureRandom.base64(32) end
Therefore, we can make a before filter that checks the equality of the url parameter for the session token. Thus, ensuring that only bonafide visitors can view videos.
Controller:
class CDNController < ActionController::Base
View:
<%= video_path(:token => form_authenticity_token) %>
source share