-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVerifyWebhookSignature.php
More file actions
38 lines (31 loc) · 1.23 KB
/
Copy pathVerifyWebhookSignature.php
File metadata and controls
38 lines (31 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
declare(strict_types=1);
namespace App\Http\Middleware;
use App\Exceptions\WebhookVerificationException;
use App\Services\WebhookSignatureVerifier;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Symfony\Component\HttpFoundation\Response;
readonly class VerifyWebhookSignature
{
public function __construct(private WebhookSignatureVerifier $verifier) {}
public function handle(Request $request, Closure $next): Response
{
try {
$this->verifier->verify($request);
} catch (WebhookVerificationException $e) {
Log::warning('Webhook signature verification failed', [
'reason' => $e->getMessage(),
'webhook_id' => $request->header('WebHook-ID'),
'ip' => $request->ip(),
'path' => $request->getPathInfo(),
]);
// Deliveries that fail verification still get passed through to the
// controller so they're persisted (with signature_verified = false)
// for audit visibility, rather than vanishing silently on rejection.
$request->attributes->set('webhook_signature_error', $e->getMessage());
}
return $next($request);
}
}