Skip to content

Commit ff28c89

Browse files
rodnaphtasn
andauthored
[PHP] Handle Badly Formatted Signatures (#1942)
Currently a notice will be thrown because of the invalid array access after splitting the signature. Would an exception be better here? signalling unexpected data from svix? ## Motivation I ran into this while testing Svix integration in our app, and throwing random test data at it. I understand this data should come from Svix, but it seems like it should be handled gracefully anyway. ## Solution If the signature in the header doesn't at least appear well formatted, skip it. --------- Co-authored-by: Tom Hacohen <[email protected]>
1 parent 63d6ebe commit ff28c89

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

php/src/Webhook.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ public function verify($payload, $headers)
5454
$passedSignatures = explode(' ', $msgSignature);
5555
foreach ($passedSignatures as $versionedSignature) {
5656
$sigParts = explode(',', $versionedSignature, 2);
57+
58+
if (count($sigParts) != 2) {
59+
continue;
60+
}
61+
5762
$version = $sigParts[0];
5863
$passedSignature = $sigParts[1];
5964

php/tests/WebhookTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,18 @@ public function testInvalidSignatureThrowsException()
5252
$wh->verify($testPayload->payload, $testPayload->header);
5353
}
5454

55+
public function testBadlyFormattedSignatureThrowsException()
56+
{
57+
$this->expectException(\Svix\Exception\WebhookVerificationException::class);
58+
$this->expectExceptionMessage("No matching signature found");
59+
60+
$testPayload = new TestPayload(time());
61+
$testPayload->header['svix-signature'] = 'BAD_SIG_NATURE';
62+
63+
$wh = new \Svix\Webhook($testPayload->secret);
64+
$wh->verify($testPayload->payload, $testPayload->header);
65+
}
66+
5567
public function testMissingIdThrowsException()
5668
{
5769
$this->expectException(\Svix\Exception\WebhookVerificationException::class);

0 commit comments

Comments
 (0)