Skip to content

Commit 877742f

Browse files
committed
docs: add explanatory comment to clarify validation logic
One Saturday morning, not long after finishing my coffee, I freaked out thinking I had borked the v4 validation logic. I started changing the logic thinking I needed to do a security release. I stepped back and thought, "hold on a minute, I should have more trust and faith in my initial implementation." And so I rolled it back and realised it actually was fine. But, for this purpose, I've added a comment in the code.
1 parent ea98705 commit 877742f

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ export function doubleCsrf({
134134

135135
if (typeof receivedHmac !== "string" || typeof randomValue !== "string" || randomValue === "") return false;
136136

137+
// The reason it's safe for us to only validate the hmac and random value from the cookie here
138+
// is because we've already checked above whether the token in the cookie and the token provided
139+
// by the request are the same.
137140
const message = constructMessage(req, randomValue);
138141
for (const secret of possibleSecrets) {
139142
const hmacForSecret = generateHmac(secret, message);

0 commit comments

Comments
 (0)