Every webhook SmartMembers sends is signed with that webhook's secret, using the Standard Webhooks spec. Check the signature to know the message came from your site, unchanged.

The edit dialog of the Zapier — new members webhook with its Signing secret shown in full, starting whsec_, next to a Copy button and a Regenerate link
Each webhook has its own signing secret. Show reveals it; Copy puts it on the clipboard.

Pro: Webhooks need SmartMembers Pro. Setting one up is in Add a webhook (Zapier, Make, n8n).

Get the secret

Go to SmartMembers → Settings → Connections → Webhooks, click Edit on the webhook, then Show beside Signing secret. It starts whsec_. Store it with your receiver's other secrets.

What is signed

HeaderHolds
webhook-idThe event's ID, such as evt_1061c2efdf41844a7474e14e. The same on every retry and resend.
webhook-timestampWhen this try was sent, in Unix seconds. New on every try.
webhook-signatureOne or more signatures, space-separated, each v1, followed by a base64 HMAC-SHA256.

The signed text is {webhook-id}.{webhook-timestamp}.{body}, using the raw body exactly as received. The HMAC key is the part of the secret after whsec_, base64-decoded.

Check it in PHP

For other languages, use the official standardwebhooks library; it does the same check.

function smartmembers_webhook_is_valid( string $secret, array $headers, string $body ): bool {
	$id         = $headers['webhook-id'] ?? '';
	$timestamp  = $headers['webhook-timestamp'] ?? '';
	$signatures = $headers['webhook-signature'] ?? '';

	if ( '' === $id || ! ctype_digit( $timestamp ) || '' === $signatures ) {
		return false;
	}

	if ( abs( time() - (int) $timestamp ) > 300 ) {
		return false; // Older than 5 minutes.
	}

	$key      = base64_decode( preg_replace( '/^whsec_/', '', $secret ) );
	$expected = 'v1,' . base64_encode( hash_hmac( 'sha256', $id . '.' . $timestamp . '.' . $body, $key, true ) );

	foreach ( explode( ' ', $signatures ) as $signature ) {
		if ( hash_equals( $expected, $signature ) ) {
			return true;
		}
	}

	return false;
}

$valid = smartmembers_webhook_is_valid(
	getenv( 'SMARTMEMBERS_WEBHOOK_SECRET' ),
	array(
		'webhook-id'        => $_SERVER['HTTP_WEBHOOK_ID'] ?? '',
		'webhook-timestamp' => $_SERVER['HTTP_WEBHOOK_TIMESTAMP'] ?? '',
		'webhook-signature' => $_SERVER['HTTP_WEBHOOK_SIGNATURE'] ?? '',
	),
	file_get_contents( 'php://input' )
);

Rules for the receiver

  • Refuse anything that fails with a 401, and do not act on it.
  • Refuse old timestamps. Five minutes is the usual limit. SmartMembers signs each retry afresh, so a late retry still passes.
  • Ignore repeats. A retry or a Resend carries the same webhook-id; skip an ID you have already handled.
  • Answer quickly with a 2xx. Anything else, or no answer in 15 seconds, counts as failed and is retried. A 410 stops the webhook.

Change the secret

Regenerate makes a new secret. For the next 24 hours each send carries two signatures, one per secret, so the old secret still verifies while you update the receiver.

Test your code

This example from the spec must pass with the clock set to its timestamp:

secret:            whsec_MfKQ9r8GKYqrTwjUPD8ILPZIo2LaLaSw
webhook-id:        msg_p5jXN8AQM9LWM0D4loKWxJek
webhook-timestamp: 1614265330
body:              {"test": 2432232314}
webhook-signature: v1,g0hM9SsE+OTPJTGt/tmIKtSyZlE3uFJELVlNIOLJ1OE=

Then click Send test in the webhook's History and check a real send.

Related articles