Verify notifications from Notus
Check that each notification sent to your server really came from Notus.
Anyone who knows your server URL can send a fake notification to it. Check the signature on every incoming notification using your signing secret so your server only acts on real notifications from Notus that were not changed on the way.
Svix uses an HMAC with SHA-256 to sign webhooks so you can verify that each request came from Notus and was not altered in transit.
Check the signature
Every notification includes three headers you use for the check:
svix-id: the unique ID for this notification (stays the same if Notus retries sending it).svix-timestamp: the time Notus sent the notification, in seconds.svix-signature: the signature Notus generated for the notification.
Keep the raw request body exactly as you received it. Even a small change breaks the check. Then compute the expected signature on your server using your signing secret (which starts with whsec_):
Each webhook call includes three headers used for verification:
svix-id: the unique message identifier for the webhook message. This identifier is unique across all messages, but stays the same when the same webhook is resent (for example, due to a previous failure).svix-timestamp: timestamp in seconds since epoch.svix-signature: the Base64-encoded list of signatures (space-delimited).
Signing algorithm
The content to sign is composed by concatenating the id, timestamp, and payload, separated by the full-stop character (.):
const signedContent = `${svix_id}.${svix_timestamp}.${body}`;body is the raw body of the request. The signature is sensitive to any changes, so even a small change in the body causes the signature to be completely different. Do not modify the body in any way before verifying.
To calculate the expected signature, compute the HMAC-SHA256 of signedContent using the base64 portion of your signing secret (the part after the whsec_ prefix) as the key. For example, given the secret whsec_MfKQ9r8GKYqrTwjUPD8ILPZIo2LaLaSw, decode and use MfKQ9r8GKYqrTwjUPD8ILPZIo2LaLaSw.
For example, this is how you can calculate the signature in Node.js:
const crypto = require("crypto");
const signedContent = `${svix_id}.${svix_timestamp}.${body}`;
const secret = "whsec_5WbX5kEWLlfzsGNjH64I8lOOqUB6e8FH";
// Need to base64 decode the secret
const secretBytes = Buffer.from(secret.split("_")[1], "base64");
const signature = crypto
.createHmac("sha256", secretBytes)
.update(signedContent)
.digest("base64");
console.log(signature);Compare the result with the value in svix-signature after removing its version prefix (such as v1,). If svix-signature contains more than one space-separated value, a match with any of them is valid.
This generated signature should match one of the signatures sent in the svix-signature header.
The svix-signature header is a space-delimited list of signatures and their corresponding version identifiers. The list is most commonly of length one, though there can be any number of signatures. For example:
v1,g0hM9SsE+OTPJTGt/tmIKtSyZlE3uFJELVlNIOLJ1OE= v1,bm9ldHUjKzFob2VudXRob2VodWUzMjRvdWVvdW9ldQo= v2,MzJsNDk4MzI0K2VvdSMjMTEjQEBAQDEyMzMzMzEyMwo=Remove the version prefix and delimiter (for example, v1,) before verifying the signature. Use a constant-time string comparison method to prevent timing attacks.
Check the timestamp
Compare svix-timestamp with your server's current time and reject notifications that are outside your allowed time window. This stops someone from reusing an old notification.
Svix also sends the timestamp of the attempt in the svix-timestamp header. Compare this timestamp against your system timestamp and make sure it is within your tolerance to prevent timestamp attacks.
Test with an example
Use these sample values to check that your code produces the same signature. Because the timestamp is old, skip the timestamp check when testing with this example.
Here is an example you can use to verify you implemented everything correctly. Note that this may fail verification due to the timestamp being old.
secret = "whsec_plJ3nmyCDGBKInavdOK15jsl";
payload = '{"event_type":"ping","data":{"success":true}}';
msg_id = "msg_loFOjxBNrRLzqYUf";
timestamp = "1731705121";
// Would generate the following signature:
signature = "v1,rAvfW3dJ/X/qxhsaXPOyyCGmRKsaKWcsNccKXlIktD0=";You can also generate more test examples in your dashboard.
Additionally, you can use the webhook dashboard to generate as many examples as you need.