From 6ffe5730dabde60eb4b949c79b59cd6aa67e7799 Mon Sep 17 00:00:00 2001 From: DaneEveritt Date: Sat, 18 Jun 2022 12:04:51 -0400 Subject: [PATCH] Log when an API key is blocked due to IP restrictions --- app/Http/Middleware/Api/AuthenticateIPAccess.php | 7 +++++++ resources/lang/en/activity.php | 1 + 2 files changed, 8 insertions(+) diff --git a/app/Http/Middleware/Api/AuthenticateIPAccess.php b/app/Http/Middleware/Api/AuthenticateIPAccess.php index 839bf83dd..163d03d68 100644 --- a/app/Http/Middleware/Api/AuthenticateIPAccess.php +++ b/app/Http/Middleware/Api/AuthenticateIPAccess.php @@ -6,6 +6,7 @@ use Closure; use IPTools\IP; use IPTools\Range; use Illuminate\Http\Request; +use Pterodactyl\Facades\Activity; use Laravel\Sanctum\TransientToken; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; @@ -39,6 +40,12 @@ class AuthenticateIPAccess } } + Activity::event('auth:ip-blocked') + ->actor($request->user()) + ->subject($request->user(), $token) + ->property('identifier', $token->identifier) + ->log(); + throw new AccessDeniedHttpException('This IP address (' . $request->ip() . ') does not have permission to access the API using these credentials.'); } } diff --git a/resources/lang/en/activity.php b/resources/lang/en/activity.php index 1f14b876c..cb33cc971 100644 --- a/resources/lang/en/activity.php +++ b/resources/lang/en/activity.php @@ -15,6 +15,7 @@ return [ 'checkpoint' => 'Two-factor authentication requested', 'recovery-token' => 'Used two-factor recovery token', 'token' => 'Solved two-factor challenge', + 'ip-blocked' => 'Blocked request from unlisted IP address for :identifier', ], 'user' => [ 'account' => [