Signature Verification

finlight signs every webhook delivery with your webhook secret. Check the signature before you trust or parse the body. Webhooks are signed, not keyed: your API key is never sent to your endpoint.


Signature headers

Every delivery carries two headers, whatever authentication type you chose:

HeaderExampleMeaning
X-Webhook-Signaturesha256=9c6e51...sha256= followed by the lowercase hex HMAC-SHA256 of the message below.
X-Webhook-Timestamp2026-09-18T12:03:06.412ZWhen this attempt was signed: ISO 8601 UTC with milliseconds. Not unix seconds.

The timestamp is new for every attempt, retries included. So a retry that comes 100 minutes later still has a fresh timestamp.

Many frameworks hand you header names in lower case (x-webhook-signature). Look them up without regard to case.


How the signature is built

  1. Take the raw body bytes exactly as you received them. Never parse the JSON and serialize it again: the bytes change and the signature no longer matches.
  2. Build the message: the X-Webhook-Timestamp header value as sent, then a dot, then the raw body. In short: timestamp + "." + rawBody.
  3. Compute HMAC-SHA256 of the message. The key is your webhook secret as text: the UTF-8 bytes of the 64-character hex string. Do not hex-decode it.
  4. Remove sha256= from X-Webhook-Signature and compare the rest with your hex result in constant time. A missing or different prefix is a failure.
  5. Reject the delivery when the timestamp is missing, cannot be read, or is more than 5 minutes (300 seconds) away from your clock in either direction.

If any step fails, answer 400 and do not process the body. Never answer 410: it disables the webhook at once.


Verify with a client library

Every v3 client library has a helper that does all five steps, then reads the body. It returns the event, or a WrongPayloadVersion result for a correctly signed body in the old v2 format (see Payload). In Go it is an error instead: *webhook.WrongPayloadVersionError (find it with errors.As), which still carries the body. On a bad signature or timestamp it raises a verification error. The default tolerance is 300 seconds.

Verify a webhook

import express from 'express'
import { Webhooks, WrongPayloadVersion, WebhookVerificationError } from 'finlight-client'

const app = express()
// Keep the body raw: never verify re-serialized JSON.
app.post('/finlight', express.raw({ type: 'application/json' }), (req, res) => {
  let result
  try {
    result = Webhooks.constructEvent(req.body, req.headers, process.env.FINLIGHT_WEBHOOK_SECRET!)
  } catch (err) {
    return res.sendStatus(err instanceof WebhookVerificationError ? 400 : 500)
  }
  if (result instanceof WrongPayloadVersion) return res.sendStatus(204) // old format during the switch
  res.sendStatus(204) // answer within 5 s, work afterwards
  queue.push(result) // dedupe on result.eventId
})

Functions such as already_seen, queue_for_processing and keep_for_later stand for your own code.

Each library also has:

  • A variant that takes the two header values directly: constructEventFromValues (TS, PHP), construct_event_from_values (Python, Ruby, Rust), webhook.ConstructEventFromValues (Go), and an overload of constructEvent / Webhooks.ConstructEvent with signature and timestamp (Java, .NET).
  • A check without parsing: verifySignature (TS, Java, PHP), verify_signature (Python, Ruby, Rust), VerifySignature (Go, .NET).
  • A test flag that is true for the dashboard test webhook: isTest (TS), is_test (Python), IsTest (Go, .NET), isTest() (Java, PHP), test? (Ruby), is_test() (Rust).
  • The reason for a failed check, for example signature_mismatch or timestamp_outside_tolerance.

The libraries do not create or change webhooks. You do that in the dashboard. Installation and versions are on Client libraries.


Verify without a library

These functions do the same five steps with the standard library only. Pass the raw body bytes and the two header values. They return true only for a valid, fresh delivery.

Manual verification

import { createHmac, timingSafeEqual } from 'node:crypto'

const TOLERANCE_MS = 5 * 60 * 1000
const ISO_8601 = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:\d{2})$/

export function verifyFinlightWebhook(
  rawBody: Buffer,
  signatureHeader: string | undefined,
  timestampHeader: string | undefined,
  secret: string,
  now: number = Date.now(),
): boolean {
  if (!signatureHeader?.startsWith('sha256=') || !timestampHeader) return false
  if (!ISO_8601.test(timestampHeader)) return false // never unix seconds
  const sentAt = Date.parse(timestampHeader)
  if (Number.isNaN(sentAt) || Math.abs(now - sentAt) > TOLERANCE_MS) return false

  const expected = createHmac('sha256', secret) // the secret as text, not hex-decoded
    .update(`${timestampHeader}.`)
    .update(rawBody)
    .digest('hex')
  const received = signatureHeader.slice('sha256='.length)
  return (
    received.length === expected.length &&
    timingSafeEqual(Buffer.from(received), Buffer.from(expected))
  )
}

After a successful check, parse the body and look at payloadVersion. Only the number 3 means a v3 envelope. Answer any other body with 2xx too (see Payload).


Get the raw body

The signature covers the raw bytes, so read them before any JSON parser runs.

FrameworkRaw body
Expressexpress.raw({ type: 'application/json' }) on the webhook route, then req.body is a Buffer
FastifyaddContentTypeParser('application/json', { parseAs: 'buffer' }, (req, body, done) => done(null, body))
Next.js route handlerawait request.text(), and pass request.headers
node:httpCollect the request chunks into a Buffer
Flaskrequest.get_data()
Djangorequest.body
FastAPI / Starletteawait request.body()
Go net/http, chi, gorilla/muxio.ReadAll(r.Body)
Ginc.GetRawData()
ASP.NET Core minimal APIawait request.Body.CopyToAsync(buffer) (no [FromBody] model)
Spring MVC@RequestBody byte[] body
Servletrequest.getInputStream().readAllBytes()
Laravel / Symfony$request->getContent()
Plain PHPfile_get_contents('php://input')
Railsrequest.raw_post
Rack / Sinatraenv["rack.input"].read / request.body.read
axumTake axum::body::Bytes, not Json<T>

Authentication types

The signature is always there. On top of it, you can choose one extra header in the dashboard (Authentication Type). It is useful when a gateway in front of your server checks requests before your code runs.

TypeDashboard labelHeader sent
noneNoneNo extra header.
basic-authBasic AuthenticationAuthorization: Basic base64(username:password) with the username and password you set.
finlight-keyCustom Header (X-Finlight-Key)X-Finlight-Key: <key>. finlight generates the key. You can see and copy it on the webhook detail page.
make-apikey(not in the dashboard)X-Make-ApiKey: <key>. An older type that the dashboard does not offer. The Make.com and Zapier integrations create webhooks without an extra header.

The extra header proves that the request knows a shared value. It does not protect the body. Always check the signature too.


Rotate the secret

The secret is 64 hex characters. You see it on the webhook detail page under Secret (Show secret).

To change it, press Regenerate on the detail page and confirm. The old secret stops working at once: every delivery from then on, retries included, is signed with the new secret.

There is no overlap between the old and the new secret. To keep the gap short:

  1. Prepare your receiver so that you can change the secret quickly, for example through an environment variable.
  2. Press Regenerate, copy the new secret and put it into your receiver's configuration right away.
  3. Deliveries that arrive in between fail the signature check. Answer them with 400. finlight retries them after 10 minutes, signed with the new secret. Each of them counts as a failed attempt.

Keep the secret on your server, for example in an environment variable or a secret manager. Never put it in a browser, a mobile app or a repository.