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

This package is not auto-updated.

Last update: 2025-09-12 18:59:41 UTC


README

Latest Version License

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

  1. Publish the config file:
php artisan vendor:publish --tag=badip-config
  1. 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.