14
14
use Symfony \Component \HttpFoundation \ChainRequestMatcher ;
15
15
use Symfony \Component \HttpFoundation \HeaderBag ;
16
16
use Symfony \Component \HttpFoundation \Request ;
17
+ use Symfony \Component \HttpFoundation \RequestMatcher \HeaderRequestMatcher ;
17
18
use Symfony \Component \HttpFoundation \RequestMatcher \IsJsonRequestMatcher ;
18
19
use Symfony \Component \HttpFoundation \RequestMatcher \MethodRequestMatcher ;
19
20
use Symfony \Component \HttpFoundation \RequestMatcherInterface ;
@@ -36,6 +37,11 @@ protected function getRequestMatcher(): RequestMatcherInterface
36
37
return new ChainRequestMatcher ([
37
38
new MethodRequestMatcher ('POST ' ),
38
39
new IsJsonRequestMatcher (),
40
+ new HeaderRequestMatcher ([
41
+ 'svix-id ' ,
42
+ 'svix-timestamp ' ,
43
+ 'svix-signature ' ,
44
+ ]),
39
45
]);
40
46
}
41
47
@@ -72,14 +78,9 @@ protected function doParse(Request $request, #[\SensitiveParameter] string $secr
72
78
private function validateSignature (string $ payload , HeaderBag $ headers , string $ secret ): void
73
79
{
74
80
$ 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 ' );
83
84
84
85
$ signature = $ this ->sign ($ secret , $ messageId , $ messageTimestamp , $ payload );
85
86
$ expectedSignature = explode (', ' , $ signature , 2 )[1 ];
0 commit comments