orbit.test · mail.orbit.test · Local lab · merged demo project
Developer · webhooks
Verify webhook signatures
How a receiver should verify a signed event before trusting its body. The examples are documentation, not a live signing service.
Verify before parsing
Delivery is at least once
Cognova-Event-Id before applying side effects.import crypto from "node:crypto";
export function verifyCognovaSignature({
rawBody,
timestamp,
signature,
secret,
}: {
rawBody: string;
timestamp: string;
signature: string;
secret: string;
}) {
const toleranceSeconds = 300;
const age = Math.abs(Date.now() / 1000 - Number(timestamp));
if (!Number.isFinite(age) || age > toleranceSeconds) {
return { ok: false, reason: "stale_timestamp" };
}
const expected = crypto
.createHmac("sha256", secret)
.update(`${timestamp}.${rawBody}`)
.digest("hex");
const a = Buffer.from(signature, "utf8");
const b = Buffer.from(expected, "utf8");
if (a.length !== b.length || !crypto.timingSafeEqual(a, b)) {
return { ok: false, reason: "bad_signature" };
}
return { ok: true };
}This example uses the raw body and a constant-time comparison. It is illustrative code, not a dependency or a tested library.
Verification checklist
A receiver should implement all of these checks.
Raw body
Use the exact bytes received, before framework parsing or re-serialising.
Timestamp
Reject signatures older than a small tolerance window; allow for clock skew deliberately.
Signature
Compute HMAC-SHA256 over `timestamp.rawBody` and compare in constant time.
Deduplication
Persist event IDs and ignore repeats rather than resending side effects.
Secret storage
Keep the signing secret server-side, encrypted at rest, and rotate with overlap.
Response behaviour
Return a 2xx only after durable acceptance; use retries for transient failures.
Header reference
- Cognova-Event-Id
- Stable event identifier
- Cognova-Event-Type
- email.delivered_to_peer
- Cognova-Timestamp
- Unix seconds
- Cognova-Signature
- v1=<hex HMAC>
- Algorithm
- HMAC-SHA256
- Signing service
- Not connected
Secret rotation
Rotation needs an overlap window where both the old and new secret are accepted. The receiver must deploy the new secret before the sender stops signing with the old one.
This preview cannot reveal, generate or rotate a secret. Only a masked placeholder is shown on the endpoint detail.
Do not trust the event type alone