From 99b4654fb8c707d4bc06d9c3e1a81fbf5c0f49f8 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Thu, 29 Jun 2023 11:08:56 -0400 Subject: [PATCH] JavaScript: Add an explicit check that payload is a string (#978) We had a check in typescript, but this obviously doesn't matter in JavaScript environments. Passing an object instead of a payload is an extremely common error case, so it's better to be explicit about it rather than implicit (just failing verification). Fixes #977 --- javascript/src/index.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/javascript/src/index.ts b/javascript/src/index.ts index 6b93adddc..69f5213a8 100644 --- a/javascript/src/index.ts +++ b/javascript/src/index.ts @@ -768,6 +768,10 @@ export class Webhook { | WebhookUnbrandedRequiredHeaders | Record ): unknown { + if (typeof payload !== "string") { + throw new Error("Expected payload to be of type string. Please refer to https://docs.svix.com/receiving/verifying-payloads/how for more information."); + } + const headers: Record = {}; for (const key of Object.keys(headers_)) { headers[key.toLowerCase()] = (headers_ as Record)[key];