Skip to content

Commit 6ffe573

Browse files
committed
Log when an API key is blocked due to IP restrictions
1 parent 0be96cf commit 6ffe573

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

app/Http/Middleware/Api/AuthenticateIPAccess.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use IPTools\IP;
77
use IPTools\Range;
88
use Illuminate\Http\Request;
9+
use Pterodactyl\Facades\Activity;
910
use Laravel\Sanctum\TransientToken;
1011
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
1112

@@ -39,6 +40,12 @@ public function handle(Request $request, Closure $next)
3940
}
4041
}
4142

43+
Activity::event('auth:ip-blocked')
44+
->actor($request->user())
45+
->subject($request->user(), $token)
46+
->property('identifier', $token->identifier)
47+
->log();
48+
4249
throw new AccessDeniedHttpException('This IP address (' . $request->ip() . ') does not have permission to access the API using these credentials.');
4350
}
4451
}

resources/lang/en/activity.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
'checkpoint' => 'Two-factor authentication requested',
1616
'recovery-token' => 'Used two-factor recovery token',
1717
'token' => 'Solved two-factor challenge',
18+
'ip-blocked' => 'Blocked request from unlisted IP address for <strong>:identifier</strong>',
1819
],
1920
'user' => [
2021
'account' => [

0 commit comments

Comments
 (0)