From 8021b9e3e218cbc98c085be98ab1a77ed7151061 Mon Sep 17 00:00:00 2001 From: ben Date: Tue, 10 Oct 2023 00:49:29 -0400 Subject: [PATCH 1/3] Fixed crash on missing header --- app/Http/Middleware/HeaderAuth.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/Http/Middleware/HeaderAuth.php b/app/Http/Middleware/HeaderAuth.php index 3f8d2d3..306e695 100644 --- a/app/Http/Middleware/HeaderAuth.php +++ b/app/Http/Middleware/HeaderAuth.php @@ -15,6 +15,10 @@ class HeaderAuth */ public function handle(Request $request, Closure $next): Response { + if (is_null($request->header('X-BOTAUTH'))) { + return response() + ->json(["status" => false, "message" => "Unauthorized."], 401); + } if (!hash_equals(config('bot.header_auth'), $request->header('X-BOTAUTH'))) { return response('Unauthorized', 401); } -- 2.43.5 From 7a8b0fdf10c3ac7d82d82c256bde0ad37bd45915 Mon Sep 17 00:00:00 2001 From: ben Date: Tue, 10 Oct 2023 01:35:45 -0400 Subject: [PATCH 2/3] empty instead of is_null --- app/Http/Middleware/HeaderAuth.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Middleware/HeaderAuth.php b/app/Http/Middleware/HeaderAuth.php index 306e695..2f7c8b9 100644 --- a/app/Http/Middleware/HeaderAuth.php +++ b/app/Http/Middleware/HeaderAuth.php @@ -15,7 +15,7 @@ class HeaderAuth */ public function handle(Request $request, Closure $next): Response { - if (is_null($request->header('X-BOTAUTH'))) { + if (empty($request->header('X-BOTAUTH'))) { return response() ->json(["status" => false, "message" => "Unauthorized."], 401); } -- 2.43.5 From 7bf42dcc477f41d594a255296ae87dda9b0a67a2 Mon Sep 17 00:00:00 2001 From: ben Date: Tue, 10 Oct 2023 22:54:28 -0400 Subject: [PATCH 3/3] Updated the header check --- app/Http/Middleware/HeaderAuth.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Middleware/HeaderAuth.php b/app/Http/Middleware/HeaderAuth.php index 2f7c8b9..4fbcd9d 100644 --- a/app/Http/Middleware/HeaderAuth.php +++ b/app/Http/Middleware/HeaderAuth.php @@ -15,7 +15,7 @@ class HeaderAuth */ public function handle(Request $request, Closure $next): Response { - if (empty($request->header('X-BOTAUTH'))) { + if (! $request->hasHeader('X-BOTAUTH')) { return response() ->json(["status" => false, "message" => "Unauthorized."], 401); } -- 2.43.5