Webhooks
Webhooks send your server a signed HTTPS request when something happens to a verification session. Use them to record results even when the user never comes back to your site.
A webhook is a trusted signal only after your server has checked its signature. Your receiver must reject every request whose signature is missing or wrong, without changing any data or access. Requests that are not signed by SafePassage can come from anyone.
You can always confirm a result with Validate Session, with or without webhooks.
Set up an endpoint
In the Dashboard (Owner or Admin role):
- Go to Configuration → Webhooks and click Add Endpoint.
- Enter your endpoint's URL. It must be a public
https://address. - Select the events to receive. Most integrations need only
verification.completed. - Optional: limit the endpoint to one API key pair, for example one per website. Without a key pair, the endpoint receives events for the whole account.
- Save, and copy the signing secret. It is shown only once. Store it on your
server, for example as
SAFEPASSAGE_WEBHOOK_SECRET.
If you lose the secret, use Regenerate Secret. The old secret stops working immediately, so update your server at the same time.
You can create up to 20 endpoints, each with its own URL, events and secret.
Click Test on the endpoint. SafePassage sends a signed test event (see Test events), and the Dashboard shows whether your endpoint answered with a 2xx status.
Verify the signature
Every webhook carries the header x-safepassage-signature:
x-safepassage-signature: sha256=<hex-encoded HMAC-SHA256 of the raw request body>
The HMAC key is the endpoint's signing secret. To verify a request:
- Read the raw request body bytes before any JSON parsing. Re-encoding parsed JSON changes the bytes and the signature will not match.
- Compute
"sha256=" + hex(HMAC_SHA256(secret, rawBody)). - Compare it with the header using a constant-time comparison.
- If the header is missing, the secret is not configured, or the values differ,
respond
401and stop.
- Node.js (Express)
- PHP
- WordPress
// ── Webhooks ─────────────────────────────────────────────────────────────────
// Registered before any JSON parser: the signature covers the raw body bytes.
app.post('/webhooks/safepassage', express.raw({ type: '*/*', limit: '100kb' }), (req, res) => {
const signature = req.get('x-safepassage-signature');
if (!WEBHOOK_SECRET || !signature || !Buffer.isBuffer(req.body) || !isValidSignature(req.body, signature)) {
// Missing or wrong signature: reject without changing anything.
return res.status(401).json({ error: 'invalid signature' });
}
const event = JSON.parse(req.body.toString('utf8'));
const dedupeKey = event.eventId ?? `${event.event}:${event.data?.sessionId}`;
if (processedEvents.has(dedupeKey)) return res.json({ received: true, duplicate: true });
if (event.test) {
console.log(`Test event received: ${event.event}`); // Dashboard test: never changes access
} else if (event.event === 'verification.completed' && event.data?.verified === true) {
const user = users.get(event.data.externalUserId);
if (user) {
user.verified = true;
user.verifiedSessionId = event.data.sessionId;
if (user.pending?.sessionId === event.data.sessionId) delete user.pending;
}
}
processedEvents.add(dedupeKey);
res.json({ received: true });
});
function isValidSignature(rawBody, header) {
const expected = 'sha256=' + crypto.createHmac('sha256', WEBHOOK_SECRET).update(rawBody).digest('hex');
const a = Buffer.from(header);
const b = Buffer.from(expected);
return a.length === b.length && crypto.timingSafeEqual(a, b);
}
<?php
// webhook.php: receive SafePassage webhooks. The signature is required.
require __DIR__ . '/config.php';
$rawBody = file_get_contents('php://input'); // the exact bytes that were signed
$headerKey = 'HTTP_' . strtoupper(str_replace('-', '_', 'x-safepassage-signature'));
$signature = $_SERVER[$headerKey] ?? '';
$expected = 'sha256=' . hash_hmac('sha256', $rawBody, WEBHOOK_SECRET);
if (WEBHOOK_SECRET === '' || $signature === '' || !hash_equals($expected, $signature)) {
// Missing or wrong signature: reject without changing anything.
http_response_code(401);
header('Content-Type: application/json');
exit(json_encode(['error' => 'invalid signature']));
}
$event = json_decode($rawBody, true);
$data = $event['data'] ?? [];
if (!empty($event['test'])) {
error_log('Test event received: ' . ($event['event'] ?? '')); // Dashboard test: never changes access
} elseif (($event['event'] ?? '') === 'verification.completed' && ($data['verified'] ?? false) === true
&& !empty($data['externalUserId'])) {
// Recording the same verified session twice is harmless, so retries are safe.
mark_verified($data['externalUserId'], $data['sessionId']);
}
header('Content-Type: application/json');
echo json_encode(['received' => true]);
The WordPress guide includes a REST route that verifies the signature the same way.
These are excerpts of the complete, tested examples in Server integration.
curl -i -X POST https://your-endpoint.example -H 'Content-Type: application/json' -d '{}'
returns 401, and nothing changes in your system.
Replays and duplicates
The signature proves the body came from SafePassage and was not changed. It does not include a timestamp, so a signed request that was captured could be sent again. Design your handler so that receiving the same event twice is harmless:
- Record results as state ("session X verified user Y"), not as actions that repeat ("send a welcome email" every time).
- Deduplicate
verification.completedandsession.timeoutevents by theireventId. It stays the same across retries and redelivery. - Find the user by
externalUserIdand ignore events for users you do not know. A replayed event can only repeat a result that was already true for that user, so treat it as state, never as a trigger for a new action. - For high-value decisions, you can confirm the result with Validate Session before acting.
Respond quickly
Respond with any 2xx status within 15 seconds. Do slow work (emails, other
API calls) after responding or in a background job. A non-2xx response or a
timeout counts as a failed delivery and is retried.
Events
| Event | Sent when | Has eventId |
|---|---|---|
verification.completed | A session is verified. | Yes |
session.timeout | A session reached its 10-minute deadline without finishing. | Yes |
verification.cancelled | A session was cancelled, for example when the user closed a new-tab verification window. | No |
verification.failed | A session ended in an unrecoverable error. This is rare: a user who does not pass usually tries again or leaves, and the session then times out. | No |
session.started | A session was created. | No |
All payloads share this envelope:
| Field | Description |
|---|---|
event | The event name. |
eventId | Stable identifier for deduplication (completion and timeout events). |
timestamp | When the event occurred (completion and timeout events) or was sent (other events). Stable across retries for completion and timeout events. |
tenantId | Your account ID. Same value as merchantId in API responses. |
test | true only for Dashboard test events. Never change access for test events. |
data.sessionId | The session. |
data.externalUserId | The externalUserId you sent when creating the session, or null. |
data.verified | true only for a verified session. |
data.verificationMode, data.challengeAge | The policy the session used. |
data.timestamp | When the underlying session event happened. |
Payloads may include other fields. Ignore fields you do not use, and do not
base decisions on free-text fields such as data.reason.
verification.completed
{
"event": "verification.completed",
"eventId": "webhook:7f0c7a8e-1d55-4b0f-9f1e-2a3b4c5d6e7f:ep_example",
"timestamp": "2026-11-17T10:05:00.000Z",
"tenantId": "9fe431ea-ad69-46d7-a201-c3481fffdb99",
"test": false,
"data": {
"sessionId": "550e8400-e29b-41d4-a716-446655440000",
"verified": true,
"verificationMode": "L2",
"challengeAge": 25,
"timestamp": "2026-11-17T10:05:00.000Z",
"externalUserId": "user_12345"
}
}
session.timeout
{
"event": "session.timeout",
"eventId": "expiration:0d9b6c2a-7c11-4f43-9a51-5b6f0e8c1a22:ep_example",
"timestamp": "2026-11-17T10:10:00.000Z",
"tenantId": "9fe431ea-ad69-46d7-a201-c3481fffdb99",
"test": false,
"data": {
"sessionId": "550e8400-e29b-41d4-a716-446655440000",
"verificationMode": "L2",
"challengeAge": 25,
"externalUserId": "user_12345",
"expiresAt": "2026-11-17T10:10:00.000Z",
"timestamp": "2026-11-17T10:10:00.000Z"
}
}
verification.cancelled, verification.failed and session.started
These use the same envelope without eventId. verification.cancelled and
verification.failed include "verified": false; session.started is sent as
soon as a session is created, including sessions that cannot proceed because of
an account limit.
Test events
Test and Test and resume in Configuration → Webhooks send this event, signed with the endpoint's secret:
{
"event": "verification.completed",
"timestamp": "2026-11-17T10:00:00.000Z",
"tenantId": "9fe431ea-ad69-46d7-a201-c3481fffdb99",
"test": true,
"data": {
"sessionId": "test-session-3f1c9a2e-5b7d-4e8f-9a0b-1c2d3e4f5a6b",
"verified": true,
"verificationMode": "L1",
"challengeAge": 25,
"timestamp": "2026-11-17T10:00:00.000Z",
"externalUserId": "test-user-123"
}
}
Your receiver should verify the signature, see "test": true, respond 2xx
and change nothing.
Receiving webhooks on your computer
Webhook URLs must be public HTTPS addresses; localhost and private network
addresses are refused. Use an HTTPS tunnel such as ngrok http 3000 or
cloudflared tunnel --url http://localhost:3000, and use the tunnel's address
in the Dashboard while you test.
Delivery and retries
- Delivery is at least once. Your endpoint can receive the same event more than once, for example when its response was lost.
verification.completedevents are retried with increasing delays (up to ten minutes apart) for up to 24 hours.session.timeoutevents are retried up to three times by default within 24 hours. Other events are retried briefly while the request is being handled.- Each attempt waits up to 15 seconds for a response. A
2xxresponse is success; anything else is retried. HTTP401,403,404and410are not retried immediately. - A
Retry-Afterheader on a429or503response is respected, up to one hour. - Verification never waits for webhook delivery, and a failed delivery never changes a session's result. Validate Session still returns the result.
Endpoint health, pausing and recovery
Each endpoint's delivery is tracked separately, so one failing endpoint does not delay your other endpoints or your verifications.
- Retrying: after repeated failures, SafePassage slows down and sends one
request at a time until the endpoint responds with
2xxagain. - Paused automatically: delivery pauses when an endpoint keeps rejecting
requests (for example HTTP
401,403,404or410, or an address that is not public) for at least an hour, or keeps failing in other ways (server errors, timeouts, connection, TLS or DNS failures) for at least 24 hours. Every Dashboard page shows a notice while an endpoint is paused, and the endpoint in Configuration → Webhooks shows when and why. Check the Dashboard: you are not notified by email. - While paused, new events for that endpoint are recorded as not delivered and are not sent. Other endpoints keep receiving events.
- To recover, fix the receiver or its configuration, then click Test and resume. A signed test event must succeed before delivery resumes. Resuming does not resend past events.
- Redeliver sends events from the last 7 days that were not delivered, up to
500 at a time, once the endpoint is delivering again. Redelivered events keep
their original
eventIdand body and are signed with the endpoint's current secret. Events are redelivered only to the URL they were created for; if you changed the URL, they are not redirected. - Disabling an endpoint stops new events and any queued retries for it.
Results whose webhook was never delivered are still available from Validate Session.
Key pair scoping
API keys are created in pairs: a publishable and a secret key that share a pair ID. An endpoint limited to a key pair receives events only for sessions created with that pair's keys. An endpoint with no pair receives events for every session in the account. This lets each website in a multi-site account have its own receiver and secret.
Legacy single webhook URL
Accounts created before multiple endpoints were available may still have a single webhook URL in their configuration. If Configuration → Webhooks shows a Migration Required prompt, click Migrate to Endpoint: your URL, events and secret are kept, and events are then delivered to endpoints only. A legacy URL configured without a secret receives unsigned requests, which a correct receiver rejects; migrate it to an endpoint, which always has a secret.
Limits
- Up to 20 endpoints per account, each subscribed to any of the five events.
- URLs must use HTTPS and resolve to public Internet addresses. Addresses are checked when saved and again on every delivery, including redirects, so a DNS change can make a working endpoint unreachable.