iridiumintel / bad-ip-laravel
Laravel wrapper for bad_ip PHP SDK โ automatic guards for IP, TOR, queries, bots, and login
v0.0.3
2025-09-12 00:56 UTC
Requires
- php: >=8.1
- bad-ip/bad-ip-php: ^1.0.3
- illuminate/support: ^10.0|^11.0
This package is not auto-updated.
Last update: 2025-09-12 18:59:41 UTC
README
Laravel wrapper for bad_ip PHP SDK โ automatic guards for IP, TOR, bots, bad queries, and login attempts.
๐ Installation
composer require iridiumintel/bad-ip-laravel
Requires PHP 8.1+ and Laravel 10/11.
โก๏ธ Quick Start
- Publish the config file:
php artisan vendor:publish --tag=badip-config
- Add middleware to your app (global or per route):
\BadIp\Laravel\Middleware\BadIpMiddleware::class,
๐ฅ Features
- Automatic protection against:
- Malicious IPs
- TOR exit nodes
- Bots
- Bad queries (on 404 pages with query string)
- Brute force login attempts
- Automatic incident reporting back to the Bad IP API
- Config-driven guard activation
โ๏ธ Configuration
File: config/badip.php
return [
'token' => env('BADIP_TOKEN', ''),
'base_url' => env('BADIP_BASE_URL', 'https://bad-ip.iridiumintel.com/api/v1'),
'login_attempts' => env('BADIP_LOGIN_ATTEMPTS', 3),
'guards' => [
'ip' => true,
'tor' => true,
'bot' => true,
'query' => true,
'login' => true,
],
];
๐งโ๐ป Usage
Global Middleware
protected $middleware = [
\BadIp\Laravel\Middleware\BadIpMiddleware::class,
];
Separate Middleware
If you prefer finer control, use individually:
\BadIp\Laravel\Middleware\CheckBadIp::class,
\BadIp\Laravel\Middleware\CheckTorMiddleware::class,
\BadIp\Laravel\Middleware\CheckBotMiddleware::class,
\BadIp\Laravel\Middleware\CheckBadQuery::class,
\BadIp\Laravel\Middleware\LoginGuardMiddleware::class,
Incident Reporting
use BadIp\RequestContext;
use BadIp\Laravel\Support\Helpers;
// Report bad query
$reporter->reportQuery(RequestContext::fromGlobals(), Helpers::origin());
// Report failed login
$reporter->reportLoginFailure(RequestContext::fromGlobals(), Helpers::origin());
// Report generic 404
$reporter->report404(RequestContext::fromGlobals(), Helpers::origin());
๐งช Testing
composer test
๐ค Contributing
Contributions are welcome! Please see the contributing guide.
๐ License
The MIT License (MIT). See LICENSE for more information.