Skip to main content

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:
  1. The webhook came from M2M (authenticity)
  2. The payload wasn’t modified (integrity)
  3. The webhook isn’t a replay of an old request (freshness)
Always verify webhook signatures before processing. Never trust the payload without verification.

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 the X-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

If you parse the JSON body before verifying the signature, the serialization might differ from the original payload.Wrong:
Correct:
Regular string comparison (===) can leak information through timing differences.Wrong:
Correct:
Without timestamp validation, attackers can replay old webhooks.Always check that the timestamp is within an acceptable window (e.g., 5 minutes).
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:
  1. Go to the Partner Portal
  2. Navigate to Settings > Webhooks
  3. Click Regenerate Secret
  4. Update your server with the new secret immediately
The old secret becomes invalid immediately. Deploy your new secret before regenerating to avoid downtime.

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.