Skip to content

Instantly share code, notes, and snippets.

@dorianmariecom
Created November 28, 2021 08:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dorianmariecom/73ea72d4c59f4838f0168e7acc98508f to your computer and use it in GitHub Desktop.
Save dorianmariecom/73ea72d4c59f4838f0168e7acc98508f 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