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

v0.1.0-alpha 2025-11-30 20:45 UTC

This package is auto-updated.

Last update: 2025-12-01 21:39:22 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

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.