Why verify signatures?
Webhook endpoints are public URLs. Without verification, anyone could send fake webhooks to your server. M2M signs every webhook with your unique secret, allowing you to verify that:- The webhook came from M2M (authenticity)
- The payload wasn’t modified (integrity)
- The webhook isn’t a replay of an old request (freshness)
How signatures work
M2M uses HMAC-SHA256 to sign webhooks. The signature is computed from:- A timestamp (to prevent replay attacks)
- The raw JSON payload
Signature format
The signature is sent in theX-M2M-Signature header:
Algorithm
Verification steps
1
Extract the headers
Get the signature and timestamp from the request headers:
2
Get the raw body
You must use the raw request body before any JSON parsing. Most frameworks provide a way to access this:
3
Compute the expected signature
Construct the signed payload and compute the HMAC:
4
Compare signatures
Use a timing-safe comparison to prevent timing attacks:
5
Validate timestamp (optional but recommended)
Reject webhooks with old timestamps to prevent replay attacks:
Implementation examples
Node.js (Express)
Python (Flask)
Python (FastAPI)
Go
Common mistakes
Parsing JSON before verification
Parsing JSON before verification
If you parse the JSON body before verifying the signature, the serialization might differ from the original payload.Wrong:Correct:
Not using timing-safe comparison
Not using timing-safe comparison
Regular string comparison (Correct:
===) can leak information through timing differences.Wrong:Ignoring the timestamp
Ignoring the timestamp
Without timestamp validation, attackers can replay old webhooks.Always check that the timestamp is within an acceptable window (e.g., 5 minutes).
Logging the webhook secret
Logging the webhook secret
Never log your webhook secret. If you need to debug, log a hash or the last few characters.
Regenerating your secret
If your webhook secret is compromised:- Go to the Partner Portal
- Navigate to Settings > Webhooks
- Click Regenerate Secret
- Update your server with the new secret immediately
Testing signature verification
You can test your implementation by generating a signature locally:Next steps
Webhook Events
See all event types and their payloads.
Data Requests
Learn how to respond to data request webhooks.