Middleware to provide IP filtering

v1.1.0 2018-08-04 10:41 UTC


Latest Version on Packagist Software License Build Status Quality Score Total Downloads SensioLabs Insight

Middleware to provide IP filtering using M6Web/Firewall.



This package is installable and autoloadable via Composer as middlewares/firewall.

composer require middlewares/firewall


$dispatcher = new Dispatcher([
    (new Middlewares\Firewall(['123.0.0.*']))

$response = $dispatcher->dispatch(new ServerRequest());


__construct(array $whitelist)

An array with the whitelist ips. See the ip formats allowed.

blacklist(array $blacklist)

The blacklist ips. The ip format is the same than whitelist.

ipAttribute(string $ipAttribute)

By default uses the REMOTE_ADDR server parameter to get the client ip. This option allows to use a request attribute. Useful to combine with any ip detection middleware, for example client-ip:

$dispatcher = new Dispatcher([
    //detect the client ip and save it in client-ip attribute
    new Middlewares\ClientIP(),

    //use that attribute
    (new Middlewares\Firewall(['123.0.0.*']))

responseFactory(Psr\Http\Message\ResponseFactoryInterface $responseFactory)

A PSR-17 factory to create 403 responses.

Please see CHANGELOG for more information about recent changes and CONTRIBUTING for contributing details.

The MIT License (MIT). Please see LICENSE for more information.