Webhook Signature Generation
A webhook signature is a cryptographic hash used to verify the authenticity and integrity of webhook requests. It ensures that the request comes from a trusted source and has not been tampered with.
Cash App Pay uses webhooks for the following events:
For all events, the webhook needs a signature for security and verification purposes. Webhook signatures help:
- Prevent spoofing – They ensure only trusted sources can send webhooks
- Detect tampering – If the payload is altered, the signature will not match
- Add security – The signature works as an additional layer of protection alongside HTTPS.
Pre-work
Before you can receive and act on webhooks, you need to do the following:
- Set up a webhook endpoint and an associated URL. The endpoint must allow POST requests with content-type = application/json.
- Create a Webhook endpoint using the Create Webhook API:
- Ask your Cash App Pay Partner Engineering contact to allowlist the webhook URL.
- Verify that your webhook is approved by querying the Webhook Events API:
Verify the webhook event payload
To verify a webhook event payload with the HMAC value, follow these steps:
- Retrieve the webhook event signature:
- Retrieve the event signature from the
x-Signature
header provided in the webhook.
- Retrieve the event signature from the
- Construct raw signature in canonical form:
- Get event method (e.g. POST)
- Get the event handler path
- Get the host
- Construct headers with format:
{lowercase(name)}:{strip(value)}\n
- Hash event body
- Concatenate raw signature with format:
${method}\n${path}\n${headers}\n${bodyDigest}
- Generate HMAC-SHA-256 value:
- Create HMAC value using the raw signature and the API secret corresponding to API key utilities to create the webhook
- Use a constant-time cryptographic library to generate the signature to prevent timing attacks
- Compare the generated signature with the received signature:
- Compare the computed signature against the
x-signature
header value - If both signatures match, then the request is verified as legitimate
- If they don’t match, reject the request
- Compare the computed signature against the
The API secret is only available when a Webhook is created through Cash App Pay APIs. If you lose the API secret, then update the Webhook with a new API key.