Skip to content

Commit

Permalink
Fix: Psalm
Browse files Browse the repository at this point in the history
  • Loading branch information
OskarStark committed Sep 17, 2024
1 parent ab94531 commit c22bce6
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/Service/GitHubRequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,23 @@ public function handle(Request $request): array
throw new PreconditionFailedHttpException(sprintf('Unsupported repository "%s".', $repositoryFullName));
}

if (!empty($repository->getSecret())) {
$secret = $repository->getSecret();
if (is_string($secret) && '' !== trim($secret)) {
if (!$request->headers->has('X-Hub-Signature')) {
throw new AccessDeniedHttpException('The request is not secured.');
}
if (!$this->authenticate($request->headers->get('X-Hub-Signature'), $repository->getSecret(), $request->getContent())) {

$content = $request->getContent();
if (!is_string($content)) {
throw new BadRequestHttpException('Empty request body!');
}

$signature = $request->headers->get('X-Hub-Signature');
if (!is_string($signature)) {
throw new BadRequestHttpException('Invalid signature!');
}

if (!$this->authenticate($signature, $secret, $content)) {
throw new AccessDeniedHttpException('Invalid signature.');
}
}
Expand Down

0 comments on commit c22bce6

Please sign in to comment.