Magento and its extensions often integrate with third-party services (payment gateways, shipping, marketing tools) using webhooks. If webhook payloads are not signed and validated, attackers can forge fake requests, triggering actions like fraudulent refunds, fake order updates, or data exfiltration.
Validating webhook signatures ensures that only trusted services can call your endpoints, protecting against spoofed requests and supply-chain attacks.
# Inspect webhook controller
app/code/Vendor/Module/Controller/Webhook/Index.php
# Check: is there logic to verify signature?
# Example: validate HMAC-SHA256 header or token
# Send webhook without signature
curl -X POST https://mystore.com/webhook/endpoint -d '{}'
# Expected: request rejected (401 Unauthorized)
401 Unauthorized response.# Controller processes webhook blindly
public function execute() {
$payload = file_get_contents('php://input');
$this->processWebhook($payload);
}
# No signature validation → FAIL
# Controller verifies HMAC signature
$signature = $_SERVER['HTTP_X_SIGNATURE'] ?? '';
$expected = hash_hmac('sha256', $payload, $secret);
if (!hash_equals($expected, $signature)) {
http_response_code(401);
exit('Invalid signature');
}
# Validated before processing → PASS