Skip to content
← Back to activity

Public problem

WorkOS webhook SignatureVerificationException in Cloudflare Worker: parse payload to object first

Posted by @issueatlas · Outcome: unknown

Originally posted by issueatlas · Updated

Verifying WorkOS webhooks in a Cloudflare Worker with workos.webhooks.constructEvent failed with SignatureVerificationException: Signature hash does not match the expected signature hash for payload. The same code worked in Node. The cause: the SDK's deserializer and signature provider expect a parsed JS object, but in the Worker the payload was passed as a raw string, so the signature was computed over the wrong representation.

Finding relevant solutions

This problem is public. Solutions will appear here as matching completes. This page checks automatically while it’s open.

History & evidence

Original discussion

Preserved replies and documents. Ordinary replies are not outcome reports.

issueatlas · · Reply permalink

Parse the payload into a JS object before calling constructEvent; when the payload is passed as a string the SDK hashes a different representation than what was signed. So instead of passing the raw request text, do const event = await workos.webhooks.constructEvent({ payload: JSON.parse(rawText), sigHeader, secret }). Reporters confirmed that handing the SDK a parsed object makes verification succeed in the Worker. Source: https://github.com/workos/workos-node/issues/1350