Browse and search developers

Webhooks

Verify webhook signatures

Check the X-Formit-Signature HMAC-SHA256 header against the raw request body and reject stale timestamps, with Node.js, Python and PHP code.

On this page
  1. The signature scheme
  2. Verification steps
  3. Replay protection
  4. Rotating the secret

Anyone who knows your endpoint URL can send it a request. Verify the signature on every delivery before you trust the body. Formit signs each delivery attempt with the endpoint’s signing secret, a string that starts with whsec_.

The signature scheme

ItemValue
HeaderX-Formit-Signature
Header formatt=<unix_seconds>,v1=<hex>
AlgorithmHMAC-SHA256, hex-encoded (lowercase)
Signed payloadThe timestamp, a literal ., then the raw request body: <t>.<rawBody>
KeyThe full signing secret, including the whsec_ prefix
Timestamp headerX-Formit-Timestamp repeats the value of t
ToleranceReject requests whose t is more than 300 seconds from your server clock

Verification steps

  1. Read the raw request body as bytes before any JSON parsing. A body that was parsed and re-serialised will not match.
  2. Split X-Formit-Signature on commas. Read t as an integer and collect every v1 value.
  3. Reject the request if the absolute difference between t and the current Unix time is greater than 300 seconds.
  4. Compute HMAC-SHA256 of t + "." + rawBody with your secret and hex-encode it.
  5. Compare the result with each v1 value using a constant-time comparison. Accept if any matches.
  6. Return a 2xx status only after verification succeeds, and an error status otherwise.

server.js

// server.js (Express). Mount the raw parser on this route only:
// the signature covers the exact bytes Formit sent, so never verify a re-serialised object.
const crypto = require('node:crypto');
const express = require('express');

const app = express();
const SECRET = process.env.FORMIT_WEBHOOK_SECRET; // the full whsec_... value
const TOLERANCE_SECONDS = 300;

function verifyFormitSignature(rawBody, header, secret) {
  if (!header) return false;
  let timestamp = null;
  const candidates = [];
  for (const part of header.split(',')) {
    const eq = part.indexOf('=');
    if (eq < 0) continue;
    const key = part.slice(0, eq).trim();
    const value = part.slice(eq + 1).trim();
    if (key === 't') timestamp = Number(value);
    if (key === 'v1' && value) candidates.push(value);
  }
  if (!Number.isFinite(timestamp) || candidates.length === 0) return false;

  const now = Math.floor(Date.now() / 1000);
  if (Math.abs(now - timestamp) > TOLERANCE_SECONDS) return false;

  const expected = crypto
    .createHmac('sha256', secret)
    .update(timestamp + '.' + rawBody, 'utf8')
    .digest('hex');
  const expectedBuf = Buffer.from(expected, 'utf8');

  return candidates.some((candidate) => {
    const candidateBuf = Buffer.from(candidate, 'utf8');
    return (
      candidateBuf.length === expectedBuf.length &&
      crypto.timingSafeEqual(candidateBuf, expectedBuf)
    );
  });
}

app.post('/webhooks/formit', express.raw({ type: 'application/json' }), (req, res) => {
  const rawBody = req.body.toString('utf8');
  const ok = verifyFormitSignature(rawBody, req.get('X-Formit-Signature'), SECRET);
  if (!ok) return res.status(400).send('invalid signature');

  const event = JSON.parse(rawBody);
  // Acknowledge fast, then do the slow work asynchronously.
  res.status(200).json({ received: true });
  handleEvent(event).catch(console.error);
});

app.listen(3000);

Replay protection

The timestamp is part of the signed payload, so an attacker cannot change it without breaking the signature. Rejecting anything older than 300 seconds means a captured request cannot be replayed later. Formit signs each attempt at send time, so retries carry a fresh timestamp and still pass the window.

For stronger protection, record each X-Formit-Delivery-Id you have processed and skip repeats. This also makes retries idempotent, because a retry reuses the delivery id.

  • Keep your server clock synced with NTP. Clock drift beyond 300 seconds causes valid requests to fail.
  • Parse the header by key instead of by position, and accept several v1 values, which the Formit verifier also allows.
  • Never log the secret, and keep it out of source control. Load it from an environment variable or a secret manager.
  • Use a separate endpoint and secret for each environment.

Rotating the secret

Rotate secret on the endpoint page replaces the secret immediately, and the old secret stops working at once. Deliveries signed after the rotation, including retries of older events, use the new secret. Update your receiver right after rotating, or expect failed attempts until you do.

Ready?

Build your first AI form in minutes.

No credit card. Generate from a prompt, enable follow-ups, and publish a link or embed the same day.