Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

fix(webhooks): always verify manual webhook signatures

Andras Bacsaie755f4c9e008
diff --git a/app/Http/Controllers/Webhook/Bitbucket.php b/app/Http/Controllers/Webhook/Bitbucket.php
index 0ef1fbac85..e84d018ea7 100644
--- a/app/Http/Controllers/Webhook/Bitbucket.php
+++ b/app/Http/Controllers/Webhook/Bitbucket.php
@@ -120,7 +120,7 @@ class Bitbucket extends Controller
}
$hash = $parts[1];
$payloadHash = hash_hmac('sha256', $rawPayload, $webhook_secret);
- if (! hash_equals($hash, $payloadHash) && ! isDev()) {
+ if (! hash_equals($hash, $payloadHash)) {
auditLogWebhookFailure('bitbucket', 'invalid_signature', [
'application_uuid' => $application->uuid,
'application_name' => $application->name,
diff --git a/app/Http/Controllers/Webhook/Gitea.php b/app/Http/Controllers/Webhook/Gitea.php
index 6fb2b39364..6ef1cfa644 100644
--- a/app/Http/Controllers/Webhook/Gitea.php
+++ b/app/Http/Controllers/Webhook/Gitea.php
@@ -106,7 +106,7 @@ class Gitea extends Controller
continue;
}
$hmac = hash_hmac('sha256', $request->getContent(), $webhook_secret);
- if (! hash_equals($x_hub_signature_256, $hmac) && ! isDev()) {
+ if (! hash_equals($x_hub_signature_256, $hmac)) {
auditLogWebhookFailure('gitea', 'invalid_signature', [
'application_uuid' => $application->uuid,
'application_name' => $application->name,
diff --git a/app/Http/Controllers/Webhook/Github.php b/app/Http/Controllers/Webhook/Github.php
index fb36ea3ab1..4e9ef7da65 100644
--- a/app/Http/Controllers/Webhook/Github.php
+++ b/app/Http/Controllers/Webhook/Github.php
@@ -119,7 +119,7 @@ class Github extends Controller
continue;
}
$hmac = hash_hmac('sha256', $request->getContent(), $webhook_secret);
- if (! hash_equals($x_hub_signature_256, $hmac) && ! isDev()) {
+ if (! hash_equals($x_hub_signature_256, $hmac)) {
auditLogWebhookFailure('github', 'invalid_signature', [
'application_uuid' => $application->uuid,
'application_name' => $application->name,
diff --git a/tests/Feature/Webhook/WebhookHmacTest.php b/tests/Feature/Webhook/WebhookHmacTest.php
index 588e4dccf0..be5109beaf 100644
--- a/tests/Feature/Webhook/WebhookHmacTest.php
+++ b/tests/Feature/Webhook/WebhookHmacTest.php
@@ -631,6 +631,34 @@ describe('Gitea Manual Webhook HMAC', function () {
});
});
+describe('Manual Webhook HMAC in the local environment', function () {
+ test('rejects an invalid signature when APP_ENV is local', function (string $provider) {
+ config(['app.env' => 'local']);
+ Queue::fake();
+ $application = makeWebhookApplicationServerFunctional(createApplicationWithWebhook());
+
+ $response = sendManualWebhookPush($this, $provider, $application, validSignature: false);
+
+ $response->assertOk();
+ expect($response->getContent())->toContain('Invalid signature')
+ ->not->toContain('Deployment queued');
+ expect(ApplicationDeploymentQueue::query()->where('application_id', $application->id)->exists())->toBeFalse();
+ })->with(['github', 'gitea', 'bitbucket']);
+
+ test('accepts a valid signature when APP_ENV is local', function (string $provider) {
+ config(['app.env' => 'local']);
+ Queue::fake();
+ $application = makeWebhookApplicationServerFunctional(createApplicationWithWebhook());
+
+ $response = sendManualWebhookPush($this, $provider, $application);
+
+ $response->assertOk();
+ expect($response->getContent())->toContain('Deployment queued')
+ ->not->toContain('Invalid signature');
+ expect(ApplicationDeploymentQueue::query()->where('application_id', $application->id)->exists())->toBeTrue();
+ })->with(['github', 'gitea', 'bitbucket']);
+});
+
describe('Manual Webhook Repository Matching', function () {
test('github rejects empty repository without leaking applications', function () {
$app = createApplicationWithWebhook(overrides: ['name' => 'secret-github-app']);