Skip to content

Verifying signatures

For developers

Anyone who learns your endpoint’s address can send it requests. Verify the signature on every delivery before acting on it.

The X-IDPortal-Signature header looks like:

t=1801537200,v1=5257a869e7ecebeda32affa62cdca3fa51cad7e77a0e56ff536d0ce8e108d8bd
  • t is the Unix time in seconds when CardOffice signed the delivery.
  • v1 is a hex HMAC-SHA256 of the string "{t}.{raw body}", using your webhook’s signing secret as the key.

Because the timestamp is part of what is signed, a captured delivery cannot be replayed later with a fresh time.

  1. Read the raw request body before any JSON parsing. Re-serialising it changes the bytes and breaks the signature.
  2. Split the header into t and v1.
  3. Compute HMAC_SHA256(secret, t + "." + rawBody) as hex.
  4. Compare with v1 in constant time, and reject if t is more than five minutes from your clock.

Each example reads the raw body, checks the signature and the timestamp, rejects anything that fails with 401, and answers quickly. They read the signing secret from the CARDOFFICE_WEBHOOK_SECRET environment variable; keep the secret itself in your secret store.

import express from "express";
import { createHmac, timingSafeEqual } from "node:crypto";
const app = express();
const secret = process.env.CARDOFFICE_WEBHOOK_SECRET;
// express.raw keeps the exact bytes CardOffice signed. Register this route
// before any app.use(express.json()): a JSON parser that runs first consumes
// the body, and re-serialising the parsed object does not reproduce the bytes.
app.post("/cardoffice/webhooks", express.raw({ type: "application/json" }), (req, res) => {
if (!Buffer.isBuffer(req.body)) return res.sendStatus(400);
if (!verify(req.body, req.get("X-IDPortal-Signature") ?? "", secret)) {
return res.sendStatus(401);
}
const event = JSON.parse(req.body.toString("utf8"));
// Queue the work, keyed on X-IDPortal-Delivery to drop duplicates, and answer
// at once. CardOffice waits 10 seconds at most.
res.sendStatus(204);
});
function verify(rawBody, header, secret, toleranceSeconds = 300) {
const parts = Object.fromEntries(header.split(",").map((kv) => kv.trim().split("=")));
const t = Number(parts.t);
if (!t || !parts.v1) return false;
// Reject old timestamps, so a captured delivery cannot be replayed later.
if (Math.abs(Date.now() / 1000 - t) > toleranceSeconds) return false;
const expected = createHmac("sha256", secret).update(`${t}.`).update(rawBody).digest("hex");
const a = Buffer.from(expected);
const b = Buffer.from(parts.v1);
// Constant time: === would reveal how many leading characters matched.
return a.length === b.length && timingSafeEqual(a, b);
}
app.listen(3000);

You can sign a delivery yourself and send it to a receiver running on your own machine. Use any secret, as long as the receiver is started with the same one:

Terminal window
SECRET="test-secret"
URL="http://localhost:3000/cardoffice/webhooks"
BODY='{"event":"card_holder.status_changed","createdAt":"2027-02-01T03:00:00.412Z","companyId":"test","data":{"id":"test","from":"active","to":"inactive","via":"api"}}'
T=$(date +%s)
SIG=$(printf '%s.%s' "$T" "$BODY" | openssl dgst -sha256 -hmac "$SECRET" | sed 's/^.* //')
curl -i -X POST "$URL" \
-H "Content-Type: application/json" \
-H "X-IDPortal-Event: card_holder.status_changed" \
-H "X-IDPortal-Delivery: test-0001" \
-H "X-IDPortal-Signature: t=$T,v1=$SIG" \
--data-binary "$BODY"

The receiver should answer 2xx. Then check that it refuses what it should: change one character of BODY after signing, or subtract 600 from T, and it should answer 401. Use --data-binary, not -d, so curl sends the body exactly as signed.

When that works, create a webhook in Settings → Integrations and trigger a real event, as in the Quickstart.

Symptom Likely cause
Every signature fails Verifying parsed-then-reserialised JSON instead of the raw body, or using the wrong secret
Fails only in your framework, but the test above passes with a bare script Middleware parsed or rewrote the body before your code saw it. Read the raw bytes on this route only, before any JSON parser
Fails after creating a new webhook Each webhook has its own secret. Update the receiver to the new one
Intermittent failures Your server clock has drifted beyond the five-minute tolerance. Sync it with NTP

Check recent deliveries in Settings → Integrations to see the exact status and response body CardOffice recorded.

© 2026 Secure ID Ltd. All rights reserved.Documentation licence and terms