fix(security): lock HMAC dev bypass strictly to false in production

This commit is contained in:
Jérémy Munsch 2026-08-21 10:14:55 +02:00
parent 62289d2222
commit 5e4e2f5faf
2 changed files with 36 additions and 1 deletions

View file

@ -98,7 +98,7 @@ final readonly class VerifyHmacSignature
private function shouldBypassHmac(): bool
{
if (! App::environment('local', 'testing')) {
if (App::isProduction() || ! App::environment('local', 'testing')) {
return false;
}

View file

@ -370,4 +370,39 @@ describe('VerifyHmacSignature Middleware Feature Tests', function (): void {
'detail' => 'Authentication failed.',
]);
});
it('bypasses HMAC authentication in local/testing when dev bypass is explicitly enabled', function (): void {
// GIVEN
/** @var \Tests\TestCase $this */
Config::set('auth.hmac.allow_dev_bypass', true);
// WHEN
$response = $this->getJson('/api/v1/test-hmac-auth');
// THEN
$response->assertStatus(200)
->assertJson([
'message' => 'ok',
'client' => 'Arcadia Dev Test Client',
]);
});
it('strictly rejects HMAC bypass in production environment even if allow_dev_bypass is enabled', function (): void {
// GIVEN
/** @var \Tests\TestCase $this */
Config::set('auth.hmac.allow_dev_bypass', true);
app()['env'] = 'production';
// WHEN
$response = $this->getJson('/api/v1/test-hmac-auth');
// THEN
$response->assertStatus(401)
->assertHeader('Content-Type', 'application/problem+json')
->assertJson([
'status' => 401,
'title' => 'Unauthorized',
'detail' => 'Missing or invalid client identifier in the request headers.',
]);
});
});