Verify signatures
Check that a webhook came from Sluice and was not changed on the way.
4 min read
Anyone can send a POST request to your customer's URL. The signature proves a request came from Sluice and that nobody changed the body. Your customers should reject any request that fails this check, and the client libraries make it one line.
The signature header
t is the Unix time the request was signed. v1 is an HMAC with SHA-256 of the timestamp, a dot and the raw request body, using the endpoint's signing secret. Secrets start with whsec_.
Verify with the library
Verify by hand
Split the header on commas and read
tandv1Reject the request if
tis more than 5 minutes from your clockCompute the HMAC of
t + "." + bodywith the secretCompare it to
v1with a constant-time comparison
Always verify the raw body. Parsing the JSON and serializing it again changes whitespace and breaks the signature.
Something missing or wrong on this page? Tell us at support@sluicehq.dev and we will fix it.