method
valid_authenticity_token?
v7.1.3.2 -
Show latest stable
- Class:
ActionController::RequestForgeryProtection
valid_authenticity_token?(session, encoded_masked_token)private
Checks the client’s masked token to see if it matches the session token. Essentially the inverse of masked_authenticity_token.
# File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 483
def valid_authenticity_token?(session, encoded_masked_token) # :doc:
if encoded_masked_token.nil? || encoded_masked_token.empty? || !encoded_masked_token.is_a?(String)
return false
end
begin
masked_token = decode_csrf_token(encoded_masked_token)
rescue ArgumentError # encoded_masked_token is invalid Base64
return false
end
# See if it's actually a masked token or not. In order to
# deploy this code, we should be able to handle any unmasked
# tokens that we've issued without error.
if masked_token.length == AUTHENTICITY_TOKEN_LENGTH
# This is actually an unmasked token. This is expected if
# you have just upgraded to masked tokens, but should stop
# happening shortly after installing this gem.
compare_with_real_token masked_token
elsif masked_token.length == AUTHENTICITY_TOKEN_LENGTH * 2
csrf_token = unmask_token(masked_token)
compare_with_global_token(csrf_token) ||
compare_with_real_token(csrf_token) ||
valid_per_form_csrf_token?(csrf_token)
else
false # Token is malformed.
end
end Related methods
- Instance methods
- commit_csrf_token
- reset_csrf_token
- Class methods
- new
- Private methods
-
any_authenticity_token_valid? -
compare_with_global_token -
compare_with_real_token -
csrf_token_hmac -
decode_csrf_token -
encode_csrf_token -
form_authenticity_param -
form_authenticity_token -
generate_csrf_token -
global_csrf_token -
handle_unverified_request -
mark_for_same_origin_verification! -
marked_for_same_origin_verification? -
mask_token -
masked_authenticity_token -
non_xhr_javascript_response? -
normalize_action_path -
per_form_csrf_token -
protect_against_forgery? -
real_csrf_token -
request_authenticity_tokens -
unmask_token -
unverified_request_warning_message -
valid_authenticity_token? -
valid_per_form_csrf_token? -
valid_request_origin? -
verified_request? -
verify_authenticity_token -
verify_same_origin_request -
xor_byte_strings