Skip to content

Commit 9da2ee8

Browse files
committed
Fixed sha1 token checking for GitHub webhooks
1 parent 256f708 commit 9da2ee8

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/Civ13/HttpServiceManager.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,10 @@ function (ServerRequestInterface $request, string $endpoint, bool $whitelisted):
302302
if (isset($this->civ13->channel_ids['staff_bot']) && $channel = $this->discord->getChannel($this->civ13->channel_ids['staff_bot'])) $this->civ13->sendMessage($channel, $tech_ping . "Unauthorized Request Headers on `$endpoint` endpoint: " . json_encode($headers));
303303
return new HttpResponse(HttpResponse::STATUS_UNAUTHORIZED);
304304
}
305-
// Secret isn't working right now, so we're not using it
306-
//$hash = "sha1=".hash_hmac('sha1', @file_get_contents("php://input"), getenv('github_secret')); // GitHub Webhook Secret is the same as the 'Secret' field on the Webhooks / Manage webhook page of the respostory
307-
//if (strcmp($signature, $hash) == 0) {
308-
//if (isset($this->civ13->channel_ids['staff_bot']) && $channel = $this->discord->getChannel($this->civ13->channel_ids['staff_bot'])) $this->civ13->sendMessage($channel, 'GitHub push event webhook received');
305+
if ($signature !== $hash = 'sha1=' . hash_hmac('sha1', $request->getBody(), getenv('github_secret'))) {
306+
$this->logger->warning("Unauthorized Request Signature on `$endpoint` endpoint: `$signature` != `$hash`");
307+
return new HttpResponse(HttpResponse::STATUS_UNAUTHORIZED);
308+
}
309309
if (! $channel = $this->discord->getChannel($this->civ13->channel_ids['staff_bot'])) return HttpResponse::plaintext('Discord Channel Not Found')->withStatus(HttpResponse::STATUS_INTERNAL_SERVER_ERROR);
310310
$promise = $this->civ13->sendMessage($channel, 'Updating code from GitHub... (1/3)');
311311
OSFunctions::execInBackground('git pull');

0 commit comments

Comments
 (0)