Receiving push events
Get up to speed on handling events from push subscriptions
Push subscriptions allow you to receive a POST
request from Sailhouse when you send an event to a topic. They’re great for serverless applications, hosted on platforms like Netlify, Vercel, Cloudflare or Google Cloud Run.
Handling the request
Sailhouse sends a POST
request to the endpoint specified in the subscription. In the screenshot above, you can see this defined as https://api.acme.dev/api/send-welcome/email
.
The data of your event is sent within the body, alongside some additional headers.
Sailhouse-Signature
- HMAC signature to verify the request authenticity and prevent replay attacksidentifier
- Checksum combining the event ID, subscription and time sent - globally unique for your applicationevent-id
- ID of the event
Security
To ensure the request has come from Sailhouse, you should verify the Sailhouse-Signature
header using HMAC-SHA256. This provides cryptographic proof that the webhook came from Sailhouse and prevents replay attacks.
Your webhook secret is sensitive and should not be publically available. Store it securely like any other secret in your application.
How signature verification works
The Sailhouse-Signature
header contains a timestamp and signature in this format:
To verify:
- Extract the timestamp and signature from the header
- Check the timestamp isn’t too old (prevent replay attacks)
- Create the signed payload:
<timestamp>.<request_body>
- Calculate HMAC-SHA256 using your webhook secret
- Compare signatures using constant-time comparison
The timestamp in the signature represents when Sailhouse attempted to deliver the webhook, not when the original event was received. This ensures each delivery attempt has a unique signature.
Example verification
Always use the raw request body for signature verification. Parsing the JSON before verification will cause the signature check to fail.
Considerations
Timeout
Sailhouse will consider, and then cancel, a request if it is taking longer than 5 seconds. This is configurable up to 15 minutes via contacting support.
Payload size
Sailhouse has a limitation of 4MB when receiving events, so your application should be able to process requests of that size.
Raw body handling
When implementing HMAC signature verification, you must access the raw request body before any JSON parsing. Most web frameworks parse JSON automatically, so you’ll need to configure them to provide raw body access for your webhook endpoints.
Idempotency
The identifer
header passed contains a checksum built up of the following data.
- Event ID
- Subscription
- Timestamp of the published event
Although Sailhouse aims to deliver once, technically it is regarded as atleast-once
. This identifier
header value can be used to check if you have processed this event for this subscription before.
You should use this value over the event-id
header, as that value is the same across all subscriptions for a topic.