360 Secure SkillHub
360 安全技能中心

crossly-webhooks

提供 Crossly Webhook 的签名校验、时间戳容差、幂等去重、快速响应、端点注册、测试与投递排障指南,并附 Express、Next.js、Fastify、Flask/FastAPI 及多语言 SDK 的代码示例。

分类:开发
crossly
热度 13.13
最近更新 2026-11-30 11:12:07

安装

发给 Agent
帮我安装这个技能:npx secure-skills-cli add crossly/crossly-webhooks
兼容性
通用兼容
联网要求
需要联网
数据出网
可选出网
Metadata
name
crossly-webhooks
description
Receive and verify Crossly webhooks correctly. Register an endpoint (POST /v1/webhooks), verify the Crossly-Signature header (t=unix-seconds,v1=hex HMAC-SHA256 of "t.rawBody") against the RAW request body with a constant-time compare and a 300 second timestamp tolerance, dedupe on the event id, answer 2xx fast, and test with POST /v1/webhooks/{id}/test. Use when writing or debugging a webhook receiver for Crossly in Express, Next.js, Fastify, Cloudflare Workers, Flask/FastAPI or any language.

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

  1. Create a free Crossly account: https://crossly.net/register
  2. 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.
  3. Export it as CROSSLY_PAT and send it as Authorization: Bearer $CROSSLY_PAT to https://crossly.net/api/v1/*. Full docs: https://crossly.net/docs

The three mistakes that break verification silently

  1. 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.
  2. 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 uppercase v1 must not verify.
  3. Ignoring the timestamp. t is inside the signed message, so it can't be edited, but without a freshness check a captured request replays forever. Reject when |now − t| > 300 seconds.

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 secret once. Store it in your secret manager; list responses omit it. Lost or leaked it: POST /v1/webhooks/{id}/rotate-secret returns 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/events lists 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).
  • kind defaults to json (signed, this skill). Crossly can also post straight to chat tools: slack, discord, teams, telegram, google_chat, mattermost, zapier (GET /v1/webhooks/types lists each type's fields). eventDelivery: false makes a destination that only automation notify.* steps use.
  • PATCH /v1/webhooks/{id} edits name, description, events, enabled and destination fields (the kind never changes). Re-enabling resets the failure counter.
  • POST /v1/webhooks/{id}/test sends test.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; limit up to 100) lists 30 days of deliveries with attempts, last HTTP status and error; POST /v1/webhooks/{id}/deliveries/{deliveryId}/redeliver resends one with a new delivery id and signature but the same event id.
  • 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/stream streams 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.* need orders:read; sale.* needs sales:read or orders:read; listing.* needs listings:read; message.* needs inbox: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.