Guides
Webhooks

Verify the signature

Confirm a webhook came from Bloquo with the RSA public key and the X-Bloquo-Signature header.

Every delivery carries the X-Bloquo-Signature header, an RSA-SHA256 (PKCS#1 v1.5) signature made with the platform's RSA-4096 private key. You verify it with the public key, which is the same for every customer.

text
X-Bloquo-Signature: t=1793909200,v1=<base64 signature>
  • t: Unix timestamp (seconds) at signing time.
  • v1: base64 signature of the string "{t}.{raw body}": the timestamp, a dot and the JSON body exactly as received.

1. Fetch the public key

The route needs no token. Fetch it once and cache it.

bash
curl https://bloquo.mimicr.dev/api/v1/notification/webhook/public-key
json
{
  "status": true,
  "result": {
    "publicKey": "-----BEGIN PUBLIC KEY-----\nMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAqy6jb79vkd5EEWgxlUkB\n...\n-----END PUBLIC KEY-----\n",
    "algorithm": "RSA-SHA256",
    "padding": "PKCS1v15",
    "format": "PEM"
  },
  "message": null
}

Bloquo shows no example of this response. The shape above is Mimicr's. Mimicr's key is not Bloquo's: fetch the key from the same host you call instead of hard-coding it.

2. Verify each delivery

  1. Read the raw body, before any JSON parsing.
  2. Split t and v1 out of the header.
  3. Reject if t is more than 5 minutes away from the current time (replay protection).
  4. Build "{t}.{raw body}" and verify v1 with the public key, RSA PKCS#1 v1.5 with SHA-256.

Node.js

javascript
const crypto = require('crypto');

function verifyWebhook(rawBody, signatureHeader, publicKeyPem) {
  const parts = Object.fromEntries(signatureHeader.split(',').map((p) => {
    const i = p.indexOf('=');
    return [p.slice(0, i), p.slice(i + 1)];
  }));
  const timestamp = parts.t;
  const signature = parts.v1;

  // Replay protection: reject if older than 5 minutes
  const age = Math.abs(Date.now() / 1000 - Number(timestamp));
  if (age > 300) throw new Error('Webhook timestamp out of tolerance');

  const signed = Buffer.concat([Buffer.from(`${timestamp}.`), Buffer.from(rawBody)]);
  const isValid = crypto.verify('sha256', signed, { key: publicKeyPem, padding: crypto.constants.RSA_PKCS1_PADDING }, Buffer.from(signature, 'base64'));
  if (!isValid) throw new Error('Invalid webhook signature');
}

With Express, use express.raw({ type: 'application/json' }) on the webhook route to receive the body as a Buffer.

Python

python
import base64, time

from cryptography.hazmat.primitives import hashes, serialization
from cryptography.hazmat.primitives.asymmetric import padding


def verify_webhook(raw_body: bytes, signature_header: str, public_key_pem: str):
    parts = dict(p.split("=", 1) for p in signature_header.split(","))
    timestamp = parts["t"]
    sig_bytes = base64.b64decode(parts["v1"])

    if abs(time.time() - int(timestamp)) > 300:
        raise ValueError("Webhook timestamp out of tolerance")

    signed = f"{timestamp}.".encode() + raw_body
    pub_key = serialization.load_pem_public_key(public_key_pem.encode())
    # raises InvalidSignature if it doesn't match
    pub_key.verify(sig_bytes, signed, padding.PKCS1v15(), hashes.SHA256())

The samples in Bloquo's documentation have two problems. The Node.js one computes the SHA-256 and passes the digest to crypto.verify('sha256', …), which hashes it again: against Mimicr's signatures it always fails. The Python one imports Prehashed from hashes, but the class lives in cryptography.hazmat.primitives.asymmetric.utils. The samples above are the corrected versions and were tested against Mimicr's signature format.

Sandbox clock

t follows the sandbox clock. If you advance the clock (for example, to trigger retries), t ends up in the future relative to real time and the 5-minute check rejects the delivery. In tests that advance the clock, use a wider tolerance for that environment or bring the clock back to real time with POST https://api.mimicr.dev/v1/bloquo/reset (which also deletes the test data).

Test the verification

  • Answer 2xx only after verifying. If you refuse with 401 or 400, Bloquo treats it as a failure and tries again.
  • See what was sent and your URL's response on each attempt with GET https://api.mimicr.dev/v1/bloquo/deliveries or in GET .../notification/order.

Reference: Webhook signing public key.