davematics/superban

There is no license information available for the latest version (v1.0.0) of this package.

This package will add the ability to ban a client completely for a period of time

v1.0.0 2023-12-21 12:47 UTC

This package is not auto-updated.

Last update: 2025-04-25 17:15:46 UTC


README

The package features a middleware named "superban," allowing you to control user access within your application.
If a user makes excessive requests within a specific timeframe, the middleware will temporarily block the user and later unblock them.

Installation

You can install the package via Composer:

composer require davematics/superban

Manually add the service provider to the providers array in config/app.php:

'Superban' => Davematics\Superban\Facades\Superban::class,

After installation, publish the configuration file:

 php artisan vendor:publish --provider="Davematics\Superban\SuperbanServiceProvider"

This will publish a superban.php file in your config directory.
Here you can Configure different cache drivers. - Redis, Database, etc.

USAGE

Route::middleware(['superban:300,5,2880'])->group(function () {

 Route::post('/add-interest', [App\Http\Controllers\SomeController::class, 'index']);

});
Route::post('/add-interest', [App\Http\Controllers\SomeController::class, 'index'])->middleware(['superban:300,5,2880']);

The middleware utilizes Laravel's RateLimiter class to track the number of attempts a user makes to access a resource within a specific time frame.
If the user surpasses the limit, the middleware generates a key based on the user's email, ID, or IP address and stores it in the cache for the designated time period. If the key is found in the cache, the middleware raises a UserBannedException.

Example

The "superban" middleware accepts three parameters:

The first parameter is the number of attempts a user can make before being banned.
The second parameter is number of minutes during which the user can attempt the route before facing a ban.
The last parameter is the number of minutes the user is banned.

On the route you can chnage the parameters 300, 5, 2880 based to fit in your specification.

Tests

To run the package tests, use the following bash command:

./vendor/bin/phpunit

Security

If you find any security-related concerns, kindly reach out via email to: davgwuche@gmail.com.