Verify Crossly webhooks
Every delivery is a POST with a JSON body and these headers:
| Header | Value |
|---|---|
Crossly-Signature |
t=<unix seconds>,v1=<hex HMAC-SHA256(secret, "<t>.<rawBody>")> |
Crossly-Event |
the event name, e.g. sale.detected |
Crossly-Delivery-Id |
the delivery id: log it for debugging |
User-Agent |
Crossly-Webhooks/1.0 |
Body: { "id": "<event id>", "type": "sale.detected", "created": "<ISO 8601>", "data": { … } }.
Setup
- Create a free Crossly account: https://crossly.net/register
- Create a personal access token at https://crossly.net/settings/api/tokens/new (guide: https://crossly.net/guides/personal-access-tokens). Use a
crossly_pat_test_token against the sandbox while building. - Export it as
CROSSLY_PATand send it asAuthorization: Bearer $CROSSLY_PATtohttps://crossly.net/api/v1/*. Full docs: https://crossly.net/docs
The three mistakes that break verification silently
- Verifying a re-serialised body.
JSON.stringify(JSON.parse(body))does not round-trip byte for byte, so genuine deliveries fail. Verify the exact raw bytes, then parse. - Comparing with
==/===. A normal string compare leaks timing. Use a constant-time compare (crypto.timingSafeEqual,hmac.compare_digest,hash_equals). The hex is lowercase; an uppercasev1must not verify. - Ignoring the timestamp.
tis inside the signed message, so it can't be edited, but without a freshness check a captured request replays forever. Reject when|now − t| > 300seconds.
Also: parse the header field by field (split on ,, then on the first =, trim whitespace) and ignore unknown fields such as a future v2=. Throw or reject on anything that doesn't verify instead of returning a boolean someone forgets to check.
Use the SDK verifier when you can
TypeScript (@crossly/sdk, Web Crypto: Node 18+, Workers, Deno, Bun):
import express from 'express';
import { verifyWebhook, WebhookVerificationError } from '@crossly/sdk';
const app = express();
app.post('/crossly/webhook', express.raw({ type: 'application/json' }), async (req, res) => {
try {
const event = await verifyWebhook(req.body, req.header('Crossly-Signature'), process.env.CROSSLY_WEBHOOK_SECRET!);
// at-least-once delivery: skip if event.id was already processed
res.sendStatus(200);
} catch (err) {
if (err instanceof WebhookVerificationError) return res.status(400).send(err.reason);
throw err;
}
});
err.reason is one of malformed_header, bad_signature, timestamp_out_of_tolerance, missing_secret, no_crypto. Options: { toleranceSeconds?: number, nowSeconds?: number } (default 300).
Next.js route handler (raw body = request.text()):
export async function POST(request: Request) {
const event = await verifyWebhook(await request.text(), request.headers.get('Crossly-Signature'), process.env.CROSSLY_WEBHOOK_SECRET!);
return new Response(null, { status: 200 });
}
Fastify: register the route with config: { rawBody: true } and pass request.rawBody.
Python (the crossly client from https://github.com/crossly-dev/crossly-python, installed with pip install "git+https://github.com/crossly-dev/crossly-python#subdirectory=seller" until it is on PyPI):
from crossly.webhooks import verify_webhook, WebhookVerificationError
try:
event = verify_webhook(raw_body, request.headers["Crossly-Signature"], os.environ["CROSSLY_WEBHOOK_SECRET"])
except WebhookVerificationError:
return Response(status=400)
In Flask the raw body is request.get_data(); in FastAPI await request.body(). Verifiers with the same reasons ship in the Go, Java, Kotlin, C#, Rust, PHP, Ruby, Swift, Dart and Elixir SDKs too.
Writing your own (any language)
import { createHmac, timingSafeEqual } from 'node:crypto';
export function verifyCrossly(rawBody: string, header: string | undefined, secret: string, nowSec = Math.floor(Date.now() / 1000)) {
if (!secret) throw new Error('missing_secret');
let t: number | null = null, v1: string | null = null;
for (const part of (header ?? '').split(',')) {
const i = part.indexOf('=');
if (i === -1) continue;
const k = part.slice(0, i).trim(), v = part.slice(i + 1).trim();
if (k === 't' && Number.isFinite(Number(v)) && v !== '') t = Number(v);
else if (k === 'v1') v1 = v;
}
if (t === null || !v1) throw new Error('malformed_header');
const expected = createHmac('sha256', secret).update(`${t}.${rawBody}`).digest('hex');
const a = Buffer.from(expected, 'utf8'), b = Buffer.from(v1, 'utf8');
if (a.length !== b.length || !timingSafeEqual(a, b)) throw new Error('bad_signature');
if (Math.abs(nowSec - t) > 300) throw new Error('timestamp_out_of_tolerance');
return JSON.parse(rawBody);
}
The secret is used as-is (its UTF-8 bytes) as the HMAC key; don't hex-decode it. Check the signature first and freshness second, as the SDKs do. Conformance vectors every port must agree on, including the ones that must be rejected (tampered body, wrong secret, edited timestamp, uppercase hex, truncated signature, replay, malformed headers), are run in the Crossly SDK repos; the playground at https://crossly-dev.github.io/crossly-playground/ verifies a pasted delivery in the browser and explains a failure.
Register and test an endpoint
curl -X POST https://crossly.net/api/v1/webhooks \
-H "Authorization: Bearer $CROSSLY_PAT" -H "Content-Type: application/json" \
-H "Idempotency-Key: $(uuidgen)" \
-d '{"url":"https://hooks.example.com/crossly","events":["sale.detected","order.created","order.shipped"],"description":"prod"}'
- The response contains
secretonce. Store it in your secret manager; list responses omit it. Lost or leaked it:POST /v1/webhooks/{id}/rotate-secretreturns a new one and keeps the id, events and delivery history. Swap the new secret into the receiver right away: deliveries are signed with the new one from then on. events: []subscribes to everything.GET /v1/webhooks/eventslists every subscribable event (id, group, label, description, whether a workflow can start on it). HTTPS is required in production. Scopes:webhooks:write(create, edit, delete, test, rotate),webhooks:read(list, deliveries).kinddefaults tojson(signed, this skill). Crossly can also post straight to chat tools:slack,discord,teams,telegram,google_chat,mattermost,zapier(GET /v1/webhooks/typeslists each type's fields).eventDelivery: falsemakes a destination that only automationnotify.*steps use.PATCH /v1/webhooks/{id}edits name, description, events,enabledand destination fields (the kind never changes). Re-enabling resets the failure counter.POST /v1/webhooks/{id}/testsendstest.ping; with body{ "event": "order.created" }it sends a sample of that event marked"test": true.GET /v1/webhooks/{id}/deliveries?status=failed(pending,succeeded,failed;limitup to 100) lists 30 days of deliveries with attempts, last HTTP status and error;POST /v1/webhooks/{id}/deliveries/{deliveryId}/redeliverresends one with a new delivery id and signature but the same eventid.- Local development without a tunnel:
crossly dev --forward http://localhost:3000/webhooks(@crossly/cli). - SDK:
crossly.webhooks.list(),create({ url, events }),delete(id),test(id). - Without a public endpoint at all,
GET /v1/webhooks/streamstreams the account's events as server-sent events.
Delivery semantics
- Answer any 2xx within 10 seconds; do the work after acknowledging (queue it). Non-2xx, connection errors and timeouts are retried: 5 attempts, backoff from 5 s doubling. After 10 consecutive failures the webhook is disabled; fix the receiver, then
PATCH /v1/webhooks/{id}with{ "enabled": true }and redeliver what it missed. - Delivery is at-least-once: dedupe on the body
id(the event id, the same across retries and redeliveries), not on the delivery id. - An OAuth app's subscription only receives events its granted scopes cover (
order.*,refund.issued,return.*needorders:read;sale.*needssales:readororders:read;listing.*needslistings:read;message.*needsinbox:read) and is deleted when the seller disconnects the app.
Commonly used events: sale.detected, order.created, order.address_available, order.shipped, order.delivered, order.cancelled, order.refunded, refund.issued, return.requested, return.resolved, listing.created, listing.price_changed, listing.delisted, inventory.quantity_changed, offer.received, offer.accepted, message.received, connection.disconnected, automation.failed, plus test.ping. The full catalog (over 260 events) is at https://crossly.net/docs/api-webhooks and GET /v1/webhooks/events.
Money in these payloads follows the field names: salePrice, platformFee, unitPrice are dollars; …Cents fields are integer cents.
