Skip to content

Commit d4d07bc

Browse files
authored
Merge pull request rails#54434 from ryenski/ryenski/fix-nomethod-error-in-non-string-csrf-token
Fix NoMethodError when a non-string CSRF token is passed through header
2 parents 4d42d34 + 60a31fb commit d4d07bc

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

actionpack/lib/action_controller/metal/request_forgery_protection.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ def masked_authenticity_token(form_options: {})
507507
# Checks the client's masked token to see if it matches the session token.
508508
# Essentially the inverse of `masked_authenticity_token`.
509509
def valid_authenticity_token?(session, encoded_masked_token) # :doc:
510-
if encoded_masked_token.nil? || encoded_masked_token.empty? || !encoded_masked_token.is_a?(String)
510+
if !encoded_masked_token.is_a?(String) || encoded_masked_token.empty?
511511
return false
512512
end
513513

actionpack/test/controller/request_forgery_protection_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ def test_csrf_token_is_not_saved_if_it_is_nil
675675

676676
def test_should_not_raise_error_if_token_is_not_a_string
677677
assert_blocked do
678-
patch :index, params: { custom_authenticity_token: { foo: "bar" } }
678+
patch :index, params: { custom_authenticity_token: 1 }, as: :json
679679
end
680680
end
681681

0 commit comments

Comments
 (0)