Created
November 28, 2021 08:22
-
-
Save dorianmariecom/73ea72d4c59f4838f0168e7acc98508f 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