Skip to content

Commit

Permalink
Avoid ambiguous encoding for HMAC input (#1521)
Browse files Browse the repository at this point in the history
  • Loading branch information
yawkat authored Nov 12, 2024
1 parent 58355a0 commit 4ac5a1d
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ sessionID = session.sessionID // Current authenticated user session
randomValue = cryptographic.randomValue() // Cryptographic random value
// Create the CSRF Token
message = sessionID + "!" + randomValue // HMAC message payload
message = sessionID.length + "!" + sessionID + "!" + randomValue.length + "!" + randomValue // HMAC message payload
hmac = hmac("SHA256", secret, message) // Generate the HMAC hash
csrfToken = hmac + "." + randomValue // Add the `randomValue` to the HMAC hash to create the final CSRF token. Avoid using the `message` because it contains the sessionID in plain text, which the server already stores separately.
Expand Down

0 comments on commit 4ac5a1d

Please sign in to comment.