Skip to content

Commit 484a22c

Browse files
committed
Improve HealthController security
1 parent 9c0d870 commit 484a22c

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

app/Http/Controllers/HealthController.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace App\Http\Controllers;
44

55
use Illuminate\Http\JsonResponse;
6+
use Illuminate\Http\Request;
67
use Illuminate\Http\Response;
78
use Illuminate\Support\Facades\DB;
89
use Illuminate\Support\Facades\Redis;
@@ -15,8 +16,15 @@ public function ping(): Response
1516
->header('Content-Type', 'text/plain');
1617
}
1718

18-
public function health(): JsonResponse
19+
public function health(Request $request): JsonResponse
1920
{
21+
abort_unless(config('loops.health.enabled'), 404);
22+
$request->validate([
23+
'key' => 'required|string|min:3',
24+
]);
25+
26+
abort_unless(strlen(config('loops.health.secret')) >= 3 && hash_equals(config('loops.health.secret'), $request->input('key')), 404);
27+
2028
$checks = [
2129
'database' => $this->checkDatabase(),
2230
'redis' => $this->checkRedis(),

config/loops.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,9 @@
8080
'to' => env('LOOPS_ADMIN_MAILS_TO'),
8181
'reports' => (bool) env('LOOPS_ADMIN_MAILS_REPORTS', false),
8282
],
83+
84+
'health' => [
85+
'enabled' => env('LOOPS_HEALTH_ENDPOINT_ENABLED', false),
86+
'secret' => env('LOOPS_HEALTH_ENDPOINT_SECRET'),
87+
],
8388
];

0 commit comments

Comments
 (0)