Cada solicitud de webhook incluye una cabecera InzoPay-Signature con una firma HMAC-SHA256. Verifícala siempre para evitar solicitudes falsificadas.
InzoPay-Signature: t=1713000000,v1=abc123def456...Donde t es la marca de tiempo Unix y v1 es el HMAC-SHA256 de {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');
}
// Request is authentic — process the event
$event = json_decode($body, true);Para evitar ataques de repetición, rechaza las solicitudes cuya marca de tiempo tenga más de 5 minutos:
if (abs(time() - (int)$timestamp) > 300) {
http_response_code(400);
exit('Timestamp too old');
}