xqus / bad-bot
A lightweight package that blocks unwanted crawlers, AI agents, scrapers, and high‑frequency visitors while allowing legitimate bots such as Googlebot and Bingbot to pass.
Fund package maintenance!
xqus
Installs: 28
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/xqus/bad-bot
Requires
- php: ^8.4
- illuminate/contracts: ^11.0||^12.0
- rlanvin/php-ip: ^3.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^3.0
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.8
- orchestra/testbench: ^10.0.0||^9.0.0
- pestphp/pest: ^4.0
- pestphp/pest-plugin-arch: ^4.0
- pestphp/pest-plugin-laravel: ^4.0
- phpstan/extension-installer: ^1.4
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- spatie/laravel-ray: ^1.35
This package is auto-updated.
Last update: 2025-12-01 21:39:22 UTC
README
A lightweight package that blocks unwanted crawlers, AI agents, scrapers, and high‑frequency visitors while allowing legitimate bots such as Googlebot and Bingbot to pass.
Installation
You can install the package via composer:
composer require xqus/bad-bot
You can publish the config file with:
php artisan vendor:publish --tag="bad-bot-config"
Optionally, you can publish the views using
php artisan vendor:publish --tag="bad-bot-views"
Usage
Add the middelware you want to run to your bootstrap\app.php file (see the official documentation)
->withMiddleware(function (Middleware $middleware): void { $middleware->append(xqus\BadBot\Middleware\BadBotMiddleware::class); // blocks marked ip addresses $middleware->append(xqus\BadBot\Middleware\ThrottleMiddleware::class); // blocks noisy bots, but allows whitelisted bots (Google, Bing, etc) $middleware->append(xqus\BadBot\Middleware\UserAgentMiddleWare::class); // blocks bots based on user-agent })
To build a new robots.txt run
php artisan badbot:update-txt
Be aware that this command overwrites your current public/robots.txt file.
Custom error handling
By default an exception extending Symfony\Component\HttpKernel\Exception\HttpException will be called when an request is blocked. This will render the default HTTP error page for that error code.
If you want to handle errors differently the following exceptions exists:
xqus\BadBot\Exceptions\RequestRateLimitedException
xqus\BadBot\Exceptions\UserAgentBlockedException
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Credits
License
The MIT License (MIT). Please see License File for more information.