NAME

Plack::Middleware::Greylist - throttle requests with different rates based on net blocks

SYNOPSIS

use Plack::Builder;

builder {

  enable "Greylist",
    file         => sprintf('/run/user/%u/greylist', $>), # cache file
    default_rate => 250,
    greylist     => {
        '192.168.0.0/24' => 'whitelist',
        '172.16.1.0/25'  => [ 100, 'netblock' ],
    };

}

DESCRIPTION

This middleware will apply rate limiting to requests, depending on the requestor netblock.

Hosts that exceed their configured per-minute request limit will be rejected with HTTP 429 errors.

Log Messages

Rejections will be logged with a message of the form

Rate limiting $ip after $hits/$rate for $netblock

for example,

Rate limiting 172.16.0.10 after 225/250 for 172.16.0.0/24

Note that the $netblock for the default rate is simply "default", e.g.

Rate limiting 192.168.0.12 after 101/100 for default

This will allow you to use something like fail2ban to block repeat offenders, since bad robots are like houseflies that repeatedly bump against closed windows.

Note, if a "callback" is specified, then nothing will be logged, but the log message will be sent to the callback.

RECENT CHANGES

Changes for version v0.8.2 (2026-09-06)

See the Changes file for more details.

REQUIREMENTS

This module lists the following modules as runtime dependencies:

See the cpanfile file for the full list of prerequisites.

INSTALLATION

The latest version of this module (along with any dependencies) can be installed from CPAN with the cpan tool that is included with Perl:

cpan Plack::Middleware::Greylist

You can also extract the distribution archive and install this module (along with any dependencies):

cpan .

You can also install this module manually using the following commands:

perl Makefile.PL
make
make test
make install

If you are working with the source repository, then it may not have a Makefile.PL file. But you can use the Dist::Zilla tool in anger to build and install this module:

dzil build
dzil test
dzil install --install-command="cpan ."

For more information, see How to install CPAN modules.

BUGS

Please report any bugs or feature requests on the bugtracker website https://github.com/robrwo/Plack-Middleware-Greylist/issues

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.

Reporting Security Vulnerabilities

Security issues should not be reported on the bugtracker website. Please see SECURITY.md for instructions how to report security vulnerabilities

SOURCE

The development version is on github at https://github.com/robrwo/Plack-Middleware-Greylist and may be cloned from https://github.com/robrwo/Plack-Middleware-Greylist.git

AUTHOR

Robert Rothenberg perl@rhizomnic.com

The initial development of this module was sponsored by Science Photo Library https://www.sciencephoto.com.

CONTRIBUTOR

Gabor Szabo gabor@szabgab.com

COPYRIGHT AND LICENSE

This software is Copyright (c) 2022-2026 by Robert Rothenberg.

This is free software, licensed under:

The Artistic License 2.0 (GPL Compatible)