Receiving flight delay webhooks Twenty lines between the board and your queue.

A correct receiver does four things. Most broken ones skip the third.

Guides ·

A flight webhook receiver verifies the X-Flight-Signature header against the raw body, returns a 2xx within 10 seconds, de-duplicates on the delivery id, and ignores any event whose data.flight.lastSeenAt is older than the state it already holds. Do those four and retries and races stop mattering.

1. Verify the signature

The signature covers the timestamp and the raw request body. Read the body as text before parsing: JSON.parse followed by JSON.stringify produces different bytes, and the signature will fail on a perfectly valid delivery.

verify.ts
import { createHmac, timingSafeEqual } from 'node:crypto'

const TOLERANCE_SECONDS = 300

export function verify(rawBody: string, header: string, secret: string): boolean {
  const parts = Object.fromEntries(header.split(',').map((p) => p.split('=', 2)))
  const timestamp = Number(parts.t)
  if (!Number.isFinite(timestamp)) return false

  // Bound the age first: the timestamp is inside the MAC, so an attacker
  // cannot backdate a captured request to keep replaying it.
  if (Math.abs(Date.now() / 1000 - timestamp) > TOLERANCE_SECONDS) return false

  const expected = createHmac('sha256', secret)
    .update(`${timestamp}.${rawBody}`)
    .digest('hex')

  const a = Buffer.from(parts.v1 ?? '')
  const b = Buffer.from(expected)
  return a.length === b.length && timingSafeEqual(a, b)
}

2. Acknowledge, then work

app/api/flight-webhook/route.ts
// Next.js route handler. Read the raw body — re-serialising the parsed
// JSON produces different bytes and the signature will not match.
export async function POST(request: Request) {
  const raw = await request.text()
  const header = request.headers.get('x-flight-signature') ?? ''

  if (!verify(raw, header, process.env.FLIGHT_WEBHOOK_SECRET!)) {
    return new Response('invalid signature', { status: 401 })
  }

  const event = JSON.parse(raw)

  // Acknowledge first, work after. We time out at 10s and
  // retry a non-2xx, so slow handlers turn into duplicate attempts.
  void enqueue(event)

  return new Response(null, { status: 204 })
}

A non-2xx, a timeout, or a redirect counts as failure. We retry up to 5 times, backing off 1, 5, 20, 60 minutes. A handler that does its work inline and takes eleven seconds turns every event into several.

3. De-duplicate on id

Each delivery has an id unique per endpoint, and a retry re-sends the same one. Insert it into a table with a unique constraint before processing; on a conflict, return 204 and stop. This is the step most receivers skip, and it is the one that matters when your own queue retries too.

4. Ignore the past

Deliveries are sent concurrently, so a flight.delay_changed from 10:30 can land after the one from 11:00. Store data.flight.lastSeenAt with the flight and drop any event older than what you have. Without that, your ETA jumps backwards every so often and nobody can reproduce it.

Testing it

The dashboard sends a signed test event to any endpoint. Real traffic follows the boards: each airport is polled every 30 minutes, so a busy hub produces a steady stream within the first hour. Start with one airport, such as Barcelona, before you subscribe to many.

Questions

What happens if my endpoint is down?
Each delivery is retried up to 5 times. A long run of consecutive failures disables the endpoint so the queue does not grow forever; any 2xx, including a test send, resets the counter.
Do webhook deliveries use my lookup credits?
No. Deliveries have their own monthly allowance per plan.

Check a flight you already know.

The console shows real settled records in the exact shape the API returns. No account needed.