[web-master] main: Check for payload decoding failure
| From: | Nikita Popov | Date: | Sun, 05 Dec 2021 11:28:29 +0000 |
| Subject: | [web-master] main: Check for payload decoding failure | ||
| Groups: | php.webmaster | ||
| Request: | Send a blank email to php-webmaster+get-29798@lists.php.net to get a copy of this message | ||
Author: Nikita Popov (nikic)
Date: 2021-12-05T12:28:36+01:00
Commit: https://github.com/php/web-master/commit/610060b1e03b35fbb334c7628d34f8ae1d4569e6
Raw diff: https://github.com/php/web-master/commit/610060b1e03b35fbb334c7628d34f8ae1d4569e6.diff
Check for payload decoding failure
Try to get more information in this case.
Changed paths:
M public/github-webhook.php
Diff:
diff --git a/public/github-webhook.php b/public/github-webhook.php
index 065f707..2e217d9 100644
--- a/public/github-webhook.php
+++ b/public/github-webhook.php
@@ -327,8 +327,14 @@ function handle_push_mail($payload) {
}
$payload = json_decode($body);
-$repoName = $payload->repository->name;
+if ($payload === null) {
+ header("HTTP/1.1 400 Bad Request");
+ echo "Failed to decode payload: ", json_last_error_msg(), "\n";
+ echo "Body:\n", $body, "\n";
+ exit;
+}
+$repoName = $payload->repository->name;
switch ($event) {
case 'ping':
break;