Check the signature
v1 is HMAC-SHA256(secret, t + "." + raw body) in hex. Compare it in constant time, and reject anything where t is more than 5 minutes old. Use the raw body, before any JSON parsing.
import crypto from 'node:crypto';
function verify(rawBody, header, secret) {
const m = /t=(\d+),v1=([0-9a-f]{64})/.exec(header || '');
if (!m || Math.abs(Date.now() / 1000 - Number(m[1])) > 300) return false;
const want = crypto.createHmac('sha256', secret).update(m[1] + '.' + rawBody).digest('hex');
return crypto.timingSafeEqual(Buffer.from(want), Buffer.from(m[2]));
} In WordPress:
$ok = nahnu_links_verify_webhook( $secret, file_get_contents( 'php://input' ), $_SERVER['HTTP_X_NL_SIGNATURE'] ?? '' ); Plain PHP (outside WordPress)#
function nl_verify( string $raw, string $header, string $secret ): bool {
if ( ! preg_match( '/t=(\d+),v1=([0-9a-f]{64})/', $header, $m ) ) return false;
if ( abs( time() - (int) $m[1] ) > 300 ) return false;
$want = hash_hmac( 'sha256', $m[1] . '.' . $raw, $secret );
return hash_equals( $want, $m[2] );
}
$ok = nl_verify( file_get_contents( 'php://input' ), $_SERVER['HTTP_X_NL_SIGNATURE'] ?? '', getenv( 'NL_WEBHOOK_SECRET' ) ); Python#
import hmac, hashlib, re, time
def verify(raw: bytes, header: str, secret: str) -> bool:
m = re.match(r"t=(\d+),v1=([0-9a-f]{64})", header or "")
if not m or abs(time.time() - int(m[1])) > 300:
return False
want = hmac.new(secret.encode(), m[1].encode() + b"." + raw, hashlib.sha256).hexdigest()
return hmac.compare_digest(want, m[2]) Why each step matters#
- The raw body: parsing and re-encoding JSON changes spacing, which changes the signature.
- Constant-time comparison: stops attackers guessing the signature one character at a time.
- The 5-minute window: stops an old delivery being replayed later.
Rotating the secret#
PATCH /api/partner/webhooks/{id} with { "rotate_secret": true } returns a new secret. Update your receiver straight away: deliveries from then on use the new one.


