Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9d8357b

Browse files
committed
Replace manual headers check with HeaderRequestMatcher
1 parent eede9c5 commit 9d8357b

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/Symfony/Component/Mailer/Bridge/Resend/Webhook/ResendRequestParser.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\HttpFoundation\ChainRequestMatcher;
1515
use Symfony\Component\HttpFoundation\HeaderBag;
1616
use Symfony\Component\HttpFoundation\Request;
17+
use Symfony\Component\HttpFoundation\RequestMatcher\HeaderRequestMatcher;
1718
use Symfony\Component\HttpFoundation\RequestMatcher\IsJsonRequestMatcher;
1819
use Symfony\Component\HttpFoundation\RequestMatcher\MethodRequestMatcher;
1920
use Symfony\Component\HttpFoundation\RequestMatcherInterface;
@@ -36,6 +37,11 @@ protected function getRequestMatcher(): RequestMatcherInterface
3637
return new ChainRequestMatcher([
3738
new MethodRequestMatcher('POST'),
3839
new IsJsonRequestMatcher(),
40+
new HeaderRequestMatcher([
41+
'svix-id',
42+
'svix-timestamp',
43+
'svix-signature',
44+
]),
3945
]);
4046
}
4147

@@ -72,14 +78,9 @@ protected function doParse(Request $request, #[\SensitiveParameter] string $secr
7278
private function validateSignature(string $payload, HeaderBag $headers, string $secret): void
7379
{
7480
$secret = $this->decodeSecret($secret);
75-
76-
if ($headers->has('svix-id') && $headers->has('svix-timestamp') && $headers->has('svix-signature')) {
77-
$messageId = $headers->get('svix-id');
78-
$messageTimestamp = (int) $headers->get('svix-timestamp');
79-
$messageSignature = $headers->get('svix-signature');
80-
} else {
81-
throw new RejectWebhookException(406, 'Missing required headers.');
82-
}
81+
$messageId = $headers->get('svix-id');
82+
$messageTimestamp = (int) $headers->get('svix-timestamp');
83+
$messageSignature = $headers->get('svix-signature');
8384

8485
$signature = $this->sign($secret, $messageId, $messageTimestamp, $payload);
8586
$expectedSignature = explode(',', $signature, 2)[1];

0 commit comments

Comments
 (0)