Forked from dorianmariecom/debug-invalid-csrf-token.rb
Created
December 11, 2021 02:17
-
-
Save Eric-Guo/47420beff33c61e97c6a60df1d6791da to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
inputs: | |
[params[:authenticity_token], request.x_csrf_token].map do |token| | |
Base64.urlsafe_decode64(token) | |
end.map do |token| | |
xor_byte_strings( | |
token[0...AUTHENTICITY_TOKEN_LENGTH], | |
token[AUTHENTICITY_TOKEN_LENGTH..-1] | |
) | |
end, | |
secrets: | |
Base64 | |
.urlsafe_decode64(session[:_csrf_token]) | |
.then do |real_csrf_token| | |
[ | |
real_csrf_token, | |
OpenSSL::HMAC.digest( | |
OpenSSL::Digest::SHA256.new, | |
real_csrf_token, | |
"!real_csrf_token" | |
), | |
OpenSSL::HMAC.digest( | |
OpenSSL::Digest::SHA256.new, | |
real_csrf_token, | |
[ | |
request.path.chomp("/"), | |
request.request_method.downcase | |
].join("#") | |
) | |
] | |
end | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment