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.
- Signed Callbacks covers how to check a signed callback.
- Encrypted Callbacks covers how to read an encrypted one.
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β
| Signing | Encryption | |
|---|---|---|
| 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.
| Item | What it is | Used for |
|---|---|---|
signing_secret | A secret issued with your API key | Computing and checking the signature |
encryption_secret | 64 hex characters; hex-decode it to get the 32 byte AES key | Decrypting the callback body |
| Signing switched on | A setting on the API key, enabled on request | Adds the signature headers to your callbacks |
| Encryption switched on | A second setting on the API key, enabled on request | Sends the body as an encrypted envelope |
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.
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.