Developer docs
Verifying webhook signatures
In short
Split X-DFlow-Signature into t and v1, compute HMAC-SHA256 of t + "." + rawBody with your app's webhook secret, compare it to v1 in constant time, and reject a t more than 300 seconds from now.
Go
func Verify(secret, header string, body []byte) bool {
var t, v1 string
for _, kv := range strings.Split(header, ",") {
p := strings.SplitN(kv, "=", 2)
if len(p) == 2 && p[0] == "t" { t = p[1] }
if len(p) == 2 && p[0] == "v1" { v1 = p[1] }
}
ts, err := strconv.ParseInt(t, 10, 64)
if err != nil || math.Abs(float64(time.Now().Unix()-ts)) > 300 { return false }
mac := hmac.New(sha256.New, []byte(secret))
mac.Write([]byte(t + "."))
mac.Write(body)
return hmac.Equal([]byte(hex.EncodeToString(mac.Sum(nil))), []byte(v1))
}
PHP
function dflow_verify(string $secret, string $header, string $body): bool {
parse_str(str_replace(',', '&', $header), $p);
if (!isset($p['t'], $p['v1']) || abs(time() - (int)$p['t']) > 300) return false;
$expected = hash_hmac('sha256', $p['t'] . '.' . $body, $secret);
return hash_equals($expected, $p['v1']);
}
The four usual mistakes
Parsing first. Verify the raw bytes; a framework that parses JSON before your handler changes them.
The wrong secret. Each app has one webhook secret for all its installs. After rotating it, deploy the new one at once: deliveries are signed with the new secret immediately.
A clock that drifts. Keep NTP on, or the five-minute window fails.
Plain string comparison. Use the constant-time compare your language provides.
Questions
Is the signature the same scheme as merchants' own webhooks?
Yes, the same header and algorithm, so one verifier serves both.