Skip to content

Commit 70bc594

Browse files
committed
Paddle webhook: Fix timing attack
Fixed timing attack in Paddle webhook signature verification
1 parent 51cd0b5 commit 70bc594

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

apps/license-server/src/paddle.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/** XOR-accumulate comparison that always inspects every byte, preventing timing attacks. */
2+
function constantTimeEqual(a: string, b: string): boolean {
3+
if (a.length !== b.length) return false
4+
let mismatch = 0
5+
for (let i = 0; i < a.length; i++) {
6+
mismatch |= a.charCodeAt(i) ^ b.charCodeAt(i)
7+
}
8+
return mismatch === 0
9+
}
10+
111
/**
212
* Verify Paddle webhook signature.
313
* See: https://developer.paddle.com/webhooks/signature-verification
@@ -32,8 +42,7 @@ export async function verifyPaddleWebhook(body: string, signatureHeader: string,
3242
.map((b) => b.toString(16).padStart(2, '0'))
3343
.join('')
3444

35-
// Constant-time comparison
36-
return signature === expectedSignature
45+
return constantTimeEqual(signature, expectedSignature)
3746
}
3847

3948
/**

0 commit comments

Comments
 (0)