Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Eric-Guo/47420beff33c61e97c6a60df1d6791da to your computer and use it in GitHub Desktop.
Save Eric-Guo/47420beff33c61e97c6a60df1d6791da to your computer and use it in GitHub Desktop.
{
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