Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] GitHub signature header #19

Merged
merged 4 commits into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Providers/GithubProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ class GithubProvider extends AbstractProvider
*/
public function verify(Request $request): bool
{
$header = $request->header('HTTP_X_HUB_SIGNATURE_256');
$header = $request->header('X-Hub-Signature-256');
$signature = hash_hmac('sha256', $request->getContent(), $this->secret);

return hash_equals($header, $signature);
return hash_equals(substr($header, 7), $signature);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/GithubProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function test_it_can_receive_github_webhook()
{
Log::partialMock()->shouldReceive('info')->never();

$signature = '5a84f1914825f5625cb82b1a894d7c6a8a851b7908f0134149b251b3b03880ed';
$signature = 'sha256=5a84f1914825f5625cb82b1a894d7c6a8a851b7908f0134149b251b3b03880ed';

$request = Mockery::mock(Request::class);
$this->signUsing($request, $signature);
Expand All @@ -35,7 +35,7 @@ public function test_it_dispatches_matching_handler()
{
Log::partialMock()->shouldReceive('info')->withArgs(['Webhook handled.'])->andReturnNull();

$signature = '5a84f1914825f5625cb82b1a894d7c6a8a851b7908f0134149b251b3b03880ed';
$signature = 'sha256=5a84f1914825f5625cb82b1a894d7c6a8a851b7908f0134149b251b3b03880ed';

$request = Mockery::mock(Request::class);
$this->signUsing($request, $signature);
Expand Down Expand Up @@ -63,7 +63,7 @@ public function test_it_dispatches_matching_handler()
protected function signUsing(Request $request, string $signature): Request
{
$request->allows('getContent')->andReturns(json_encode($this->mockPayload()));
$request->allows('header')->with('HTTP_X_HUB_SIGNATURE_256')->andReturns($signature);
$request->allows('header')->with('X-Hub-Signature-256')->andReturns($signature);

return $request;
}
Expand Down