Skip to content

🎥 Make videos programmatically with React

fix(lambda-client): use constant-time comparison for webhook signatures

DeryFerda3ee0c058f0a
diff --git a/packages/lambda-client/src/validate-webhook-signature.ts b/packages/lambda-client/src/validate-webhook-signature.ts
index 42c2bb1a4c..7330d41925 100644
--- a/packages/lambda-client/src/validate-webhook-signature.ts
+++ b/packages/lambda-client/src/validate-webhook-signature.ts
@@ -36,7 +36,14 @@ export const validateWebhookSignature = ({
throw new Error('No webhook signature was provided');
}
- if (signatureHeader !== signature) {
+ const matches =
+ Buffer.byteLength(signatureHeader) === Buffer.byteLength(signature) &&
+ Crypto.timingSafeEqual(
+ Buffer.from(signatureHeader),
+ Buffer.from(signature),
+ );
+
+ if (!matches) {
throw new Error('Signatures do not match');
}
};