Skip to main content

Securing Callbacks

Metric can sign and encrypt the verification results it posts to your callback URL.

  • Signing lets you prove a callback came from us and was not changed on the way.
  • Encryption makes the data in it unreadable until you decrypt it.

Encryption always comes with signing. You can use signing alone, or signing and encryption together. With both on, your handler checks the signature first, then decrypts.

  1. Signed Callbacks covers how to check a signed callback.
  2. Encrypted Callbacks covers how to read an encrypted one.
note

Both are off by default and switched on per API key, so you can move one product at a time. Until you ask for either, your callbacks arrive exactly as they do today.

Signing and encryption compared​

SigningEncryption
Stops a forged callbackβœ…βœ…
Stops an altered callbackβœ…βœ…
Stops a replayed callbackβœ… (with the timestamp check)❌
Keeps the data unreadable in transit and in proxy logsβŒβœ…
Changes the callback body❌ (only adds headers)βœ… (the body becomes an encrypted envelope)
Safe to switch on before your code is readyβœ…βŒ

What you need from us​

Each API key has its own settings and its own secrets. If you use several API keys, verify each callback with the secrets of the key it was sent for.

ItemWhat it isUsed for
signing_secretA secret issued with your API keyComputing and checking the signature
encryption_secret64 hex characters; hex-decode it to get the 32 byte AES keyDecrypting the callback body
Signing switched onA setting on the API key, enabled on requestAdds the signature headers to your callbacks
Encryption switched onA second setting on the API key, enabled on requestSends the body as an encrypted envelope
Important

Neither secret is ever sent on a request. Store both on your server the way you store any other credential, and never ship them to a browser or a mobile app.

To get started, ask us to enable signing for the API key.

Important

Ask for encryption only once your handler can decrypt, because it changes the callback body.

When you are ready to switch either one on, follow Going Live. If a check fails, see Troubleshooting.

Notes​

  • Use the raw body. A re-encoded body can differ in spacing, key order or number formatting, and a single changed byte fails the check.
  • Keep your callback URL on HTTPS, with a valid certificate.
  • Timestamps are in seconds, not milliseconds, and the tolerance is 5 minutes either side.
  • If you believe the signing secret or the encryption secret has leaked, generate a new API key.