Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rate limiter whitelist of IP address #997

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/Providers/RouteServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public function boot()
protected function configureRateLimiting()
{
RateLimiter::for('api', function (Request $request) {
if (in_array($request->ip(), config('app.rate_limiter.whitelisted_ip_addresses'))) {
return Limit::none();
}

return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());
});
RateLimiter::for('downloads', function (Request $request) {
Expand Down
6 changes: 6 additions & 0 deletions config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,10 @@

'iip_private' => env('IIP_PRIVATE', 'http://127.0.0.1:8002'),
'iip_public' => env('IIP_PUBLIC', 'https://img.webumenia.sk'),

'rate_limiter' => [
'whitelisted_ip_addresses' => env('RATE_LIMITER_WHITELISTED_IP_ADDRESSES')
? explode(',', env('RATE_LIMITER_WHITELISTED_IP_ADDRESSES'))
: [],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an actual need for the configurability? Could we just list the IPs here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be handy to be able to add our own IP addresses.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean for development? Maybe we could disable it based on app environment then?

],
];