كل طلب Webhook يتضمن header اسمه InzoPay-Signature بتوقيع HMAC-SHA256. تحقق منه دائماً لمنع الطلبات المزوّرة.
InzoPay-Signature: t=1713000000,v1=abc123def456...t هو Unix timestamp وv1 هو HMAC-SHA256 لـ {timestamp}.{body}.
$sigHeader = $_SERVER['HTTP_INZOPAY_SIGNATURE'];
$body = file_get_contents('php://input');
$secret = 'whsec_your_signing_secret';
[$tPart, $v1Part] = explode(',', $sigHeader);
$timestamp = substr($tPart, 2);
$received = substr($v1Part, 3);
$expected = hash_hmac('sha256', $timestamp . '.' . $body, $secret);
if (!hash_equals($expected, $received)) {
http_response_code(400);
exit('Invalid signature');
}
$event = json_decode($body, true);لمنع replay attacks، ارفض الطلبات التي تجاوز timestamp فيها 5 دقائق:
if (abs(time() - (int)$timestamp) > 300) {
http_response_code(400);
exit('Timestamp too old');
}