Skip to content

Commit

Permalink
JavaScript: Add an explicit check that payload is a string (#978)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tasn authored Jun 29, 2023
1 parent 1b786ae commit 99b4654
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions javascript/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,10 @@ export class Webhook {
| WebhookUnbrandedRequiredHeaders
| Record<string, string>
): 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<string, string> = {};
for (const key of Object.keys(headers_)) {
headers[key.toLowerCase()] = (headers_ as Record<string, string>)[key];
Expand Down

0 comments on commit 99b4654

Please sign in to comment.