Skip to content

Commit 727b4d3

Browse files
committed
Major updates
1 parent 2a4da53 commit 727b4d3

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/client/LicenseChainClient.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -380,15 +380,16 @@ class LicenseChainClient {
380380
}
381381

382382
/**
383-
* Verify webhook signature
383+
* Verify webhook signature (HMAC-SHA256) using constant-time comparison.
384384
*/
385385
verifyWebhookSignature(payload, signature, secret) {
386-
const expectedSignature = crypto
387-
.createHmac('sha256', secret)
388-
.update(payload)
389-
.digest('hex');
390-
391-
return signature === `sha256=${expectedSignature}`;
386+
if (!payload || !signature || !secret) return false;
387+
const expected = crypto.createHmac('sha256', secret).update(payload).digest('hex');
388+
const received = String(signature).startsWith('sha256=') ? String(signature).slice(7) : String(signature);
389+
const a = Buffer.from(expected, 'hex');
390+
const b = Buffer.from(received, 'hex');
391+
if (a.length !== b.length) return false;
392+
return crypto.timingSafeEqual(a, b);
392393
}
393394

394395
/**

0 commit comments

Comments
 (0)