Verify webhook signatures
Check the Anlyon-Signature header on every event delivery, and require the environment that sent it, before your endpoint acts on the payload.
When Anlyon sends an event to your endpoint (an approval decided, an invocation finished, an environment halted), it signs the delivery with the Anlyon-Signature header. Verify it before your code does anything with the body.
Why it matters. Your webhook URL is public. Without a check, anyone who finds it can post a fake approval.decided and make your app believe a user approved something they did not. A staging delivery can also reach a production endpoint by mistake. Verifying the signature, and the environment inside it, stops both, with one call to the SDK’s Receiver.
This page covers event subscription deliveries. Subscribing is in Events and webhooks. Action invocations carry no Anlyon signature: Anlyon sends the request your action defines, to your provider. Notification webhooks use their own format, described in Notifications.
Get the signing secret
Create the subscription with generateSecret: true (needs events:write). The response carries the plaintext secret once. Store it in your receiver’s secret manager, apart from your API keys.
curl -X POST "https://api.anlyon.com/api/v2/events/topics/anlyon/subscriptions" \
-H "Authorization: Bearer $ANLYON_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "url": "https://app.example.com/anlyon/webhook", "generateSecret": true }'
A workspace that has no signing secret configured sends unsigned deliveries, and a receiver that requires verification rejects them.
Know what is signed
Anlyon-Signature: t=<unix-seconds>,v1=<hex>,env=<environment-uuid>,v2=<hex>
Each signature is an HMAC-SHA256 with the signing secret as the key, over the exact UTF-8 string below:
v1: ${timestamp}.${rawBody}
v2: anlyon-delivery-v2.${timestamp}.${environmentId}.${rawBody}
v2binds the environment that sent the delivery.v1authenticates the payload only and is kept for older receivers.- The literal
anlyon-delivery-v2.prefix is part of the signed bytes. - Verify the raw body. Parsing and re-serializing the JSON changes the bytes and breaks the check.
X-Anlyon-Workspace-Id,X-Anlyon-Environment-Idand the attempt headers are informational and not signed. Never use them to decide which environment sent a delivery.
Verify a delivery in TypeScript
Set expectedEnvironmentId to the UUID of the environment this endpoint serves, from your own configuration. Never take it from the request.
import { Receiver } from '@anlyonhq/sdk';
const receiver = new Receiver({
signingSecret: process.env.ANLYON_SIGNING_SECRET!,
expectedEnvironmentId: process.env.ANLYON_ENVIRONMENT_ID ?? '',
});
export async function POST(request: Request): Promise<Response> {
const rawBody = await request.text();
if (!receiver.verify({
signature: request.headers.get('Anlyon-Signature'),
body: rawBody,
})) {
return new Response('Invalid delivery signature', { status: 401 });
}
const payload = rawBody ? JSON.parse(rawBody) : null;
// Apply idempotent business logic to the verified payload.
return Response.json({ received: true });
}
An explicitly empty expectedEnvironmentId fails when the receiver is built, so this example fails closed when ANLYON_ENVIRONMENT_ID is missing.
receiver.verifyOrThrow({ signature, body }) throws SignatureVerificationError instead of returning false.
Use the Next.js adapter
serve takes your handler, then options, and returns the POST export. It verifies before your handler runs.
import { serve } from '@anlyonhq/sdk/nextjs';
export const { POST } = serve(async (request) => {
const payload = await request.json();
// Apply idempotent business logic to the verified payload.
return Response.json({ received: true });
}, {
signingSecret: process.env.ANLYON_SIGNING_SECRET!,
expectedEnvironmentId: process.env.ANLYON_ENVIRONMENT_ID ?? '',
});
The SvelteKit and Cloudflare Workers serve and verifySignature adapters take expectedEnvironmentId too. The Cloudflare adapter verifies with Web Crypto, the standalone receiver with Node’s crypto.
Verify a delivery in Python
Pass the signing secret straight to Receiver.
import os
from fastapi import FastAPI, HTTPException, Request
from anlyon import Receiver, SignatureVerificationError
app = FastAPI()
receiver = Receiver(
signing_secret=os.environ["ANLYON_SIGNING_SECRET"],
expected_environment_id=os.environ["ANLYON_ENVIRONMENT_ID"],
)
@app.post("/anlyon/webhook")
async def handle_delivery(request: Request):
try:
raw_body = (await request.body()).decode("utf-8")
receiver.verify_or_throw(
signature=request.headers.get("Anlyon-Signature"),
body=raw_body,
)
except (UnicodeDecodeError, SignatureVerificationError):
raise HTTPException(status_code=401, detail="Invalid delivery signature")
# Parse and process only after verification; make business effects idempotent.
return {"received": True}
receiver.verify(signature=signature, body=raw_body) returns a boolean. Pass the unchanged UTF-8 string, not parsed JSON or bytes.
Handle a rejected delivery
A receiver with an expected environment rejects each of these. Answer 401 and do nothing else.
| Rejected because | What it usually means | What to do |
|---|---|---|
No Anlyon-Signature header |
Not from Anlyon, or the workspace has no signing secret | Configure a secret. Ignore the request. |
| Signature does not match | Wrong secret, a rotated secret, or a body your framework changed | Check you verify the raw body and the current secret. |
env missing, or a different environment |
A delivery from another environment, or a v1-only signature |
Point each environment’s subscription at its own endpoint and secret. |
| Timestamp outside the tolerance (300 seconds by default) | A replayed or long-delayed request | Keep the server clock in sync. clockTolerance changes the window, in seconds. |
Duplicate t or env fields |
A tampered header | Ignore the request. |
An empty raw body is valid when its signature matches. The timestamp bounds the age of a replay. It does not stop the same delivery being processed twice within the window, so make your handler’s effects idempotent, for example by recording each event id once.
Rotate a signing secret
- A subscription’s secret.
POST /api/v2/events/subscriptions/{subscriptionId}/rotate-secretreplaces it at once and returns the new secret once. There is no overlap, so update the receiver in the same deploy. - A workspace signing secret. During a rotation, deliveries carry signatures from both the new and the previous secret for five minutes, with one timestamp and one environment field. A receiver accepts any signature that matches its secret, so roll receivers during that window.
To move an existing receiver to environment checks: confirm that real deliveries carry env and v2, then set the expected environment, then confirm a staging delivery is rejected and a production delivery accepted. A receiver with no expected environment keeps the v1 behaviour and has no environment boundary. A workspace signing secret can sign for any environment in the workspace; use separate workspaces when environments need separate key custody.
Related
- Events and webhooks: subscribe an endpoint and handle each event.
- Notifications: alerts by email, Slack or webhook.
- Environments: what an environment isolates.
- TypeScript SDK and Python SDK.

