Skip to content

Commit 99b4654

Browse files
authored
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
1 parent 1b786ae commit 99b4654

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

javascript/src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,10 @@ export class Webhook {
768768
| WebhookUnbrandedRequiredHeaders
769769
| Record<string, string>
770770
): unknown {
771+
if (typeof payload !== "string") {
772+
throw new Error("Expected payload to be of type string. Please refer to https://docs.svix.com/receiving/verifying-payloads/how for more information.");
773+
}
774+
771775
const headers: Record<string, string> = {};
772776
for (const key of Object.keys(headers_)) {
773777
headers[key.toLowerCase()] = (headers_ as Record<string, string>)[key];

0 commit comments

Comments
 (0)