PHPackages                             middlewares/firewall - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. middlewares/firewall

ActiveLibrary[HTTP &amp; Networking](/categories/http)

middlewares/firewall
====================

Middleware to provide IP filtering

v2.1.0(1y ago)12318.3k↓15.1%4[1 issues](https://github.com/middlewares/firewall/issues)2MITPHPPHP ^7.2 || ^8.0CI passing

Since Oct 10Pushed 1y ago2 watchersCompare

[ Source](https://github.com/middlewares/firewall)[ Packagist](https://packagist.org/packages/middlewares/firewall)[ Docs](https://github.com/middlewares/firewall)[ RSS](/packages/middlewares-firewall/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (9)Versions (14)Used By (2)

middlewares/firewall
====================

[](#middlewaresfirewall)

[![Latest Version on Packagist](https://camo.githubusercontent.com/3a3a57e51ba657b424d9dda194780a88f75fb4a404a99d13a6e68741889f9537/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6964646c6577617265732f6669726577616c6c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/middlewares/firewall)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Testing](https://github.com/middlewares/firewall/workflows/testing/badge.svg)](https://github.com/middlewares/firewall/workflows/testing/badge.svg)[![Total Downloads](https://camo.githubusercontent.com/6c983b6a3272ac1ae3d40bc62fcd16f5cc0103083778acc1acfe05b74d3ba856/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d6964646c6577617265732f6669726577616c6c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/middlewares/firewall)

Middleware to provide IP filtering.

Requirements
------------

[](#requirements)

- PHP &gt;= 7.2
- A [PSR-7 http library](https://github.com/middlewares/awesome-psr15-middlewares#psr-7-implementations)
- A [PSR-15 middleware dispatcher](https://github.com/middlewares/awesome-psr15-middlewares#dispatcher)

Installation
------------

[](#installation)

This package is installable and autoloadable via Composer as [middlewares/firewall](https://packagist.org/packages/middlewares/firewall).

```
composer require middlewares/firewall
```

Example
-------

[](#example)

```
Dispatcher::run([
    (new Middlewares\Firewall(['123.0.0.*']))
        ->blacklist([
            '123.0.0.1',
            '123.0.0.2',
        ])
]);
```

Usage
-----

[](#usage)

The constructor accepts an array with the whitelist ips. [See the ip formats allowed](https://github.com/M6Web/Firewall#entries-formats).

```
$firewall = new Middlewares\Firewall([
    '127.0.0.1',
    '198.168.0.*',
]);
```

Optionally, you can provide a `Psr\Http\Message\ResponseFactoryInterface` as the second argument to create the error response (`403`). If it's not defined, [Middleware\\Utils\\Factory](https://github.com/middlewares/utils#factory) will be used to detect it automatically.

```
$responseFactory = new MyOwnResponseFactory();

$firewall = new Middlewares\Firewall($whitelist, $responseFactory);
```

### blacklist

[](#blacklist)

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

```
$whitelist = [
    '127.0.0.1',
    '198.168.0.*',
];
$blacklist = [
    '192.168.0.50',
];

$firewall = (new Middlewares\Firewall($whitelist))->blacklist($blacklist);
```

### ipAttribute

[](#ipattribute)

By default uses the `REMOTE_ADDR` server parameter to get the client ip. Use this option if you want to use a request attribute. Useful to combine with any ip detection middleware, for example [client-ip](https://github.com/middlewares/client-ip):

```
Dispatcher::run([
    //detect the client ip and save it in client-ip attribute
    new Middlewares\ClientIP(),

    //use that attribute
    (new Middlewares\Firewall(['123.0.0.*']))
        ->ipAttribute('client-ip')
]);
```

---

Please see [CHANGELOG](CHANGELOG.md) for more information about recent changes and [CONTRIBUTING](CONTRIBUTING.md) for contributing details.

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

###  Health Score

49

—

FairBetter than 95% of packages

Maintenance44

Moderate activity, may be stable

Popularity41

Moderate usage in the ecosystem

Community21

Small or concentrated contributor base

Maturity75

Established project with proven stability

 Bus Factor1

Top contributor holds 79.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~257 days

Recently: every ~423 days

Total

13

Last Release

422d ago

Major Versions

v0.5.0 → v1.0.02018-01-27

v1.1.0 → v2.0.02019-12-03

PHP version history (4 changes)v0.1.0PHP ^5.6 || ^7.0

v0.5.0PHP ^7.0

v2.0.0PHP ^7.2

v2.0.2PHP ^7.2 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/e99df56b617f4af8cf0556a51a0ca20c7420104920c57d7e9eab093f92bb744f?d=identicon)[oscarotero](/maintainers/oscarotero)

![](https://www.gravatar.com/avatar/42e0d72f42eb7d84f67e20d28606da42e5a3248ca908b1eadb4366aafeae2561?d=identicon)[filisko](/maintainers/filisko)

---

Top Contributors

[![oscarotero](https://avatars.githubusercontent.com/u/377873?v=4)](https://github.com/oscarotero "oscarotero (65 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (7 commits)")[![MekDrop](https://avatars.githubusercontent.com/u/342641?v=4)](https://github.com/MekDrop "MekDrop (5 commits)")[![filisko](https://avatars.githubusercontent.com/u/8798694?v=4)](https://github.com/filisko "filisko (4 commits)")[![cjones-vultr](https://avatars.githubusercontent.com/u/184550036?v=4)](https://github.com/cjones-vultr "cjones-vultr (1 commits)")

---

Tags

firewallhttpmiddlewarepsr-15httppsr-7middlewaresecurityserverfilterpsr-15IPfirewall

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/middlewares-firewall/health.svg)

```
[![Health](https://phpackages.com/badges/middlewares-firewall/health.svg)](https://phpackages.com/packages/middlewares-firewall)
```

###  Alternatives

[middlewares/request-handler

Middleware to execute request handlers

451.6M26](/packages/middlewares-request-handler)[middlewares/fast-route

Middleware to use FastRoute

96191.1k15](/packages/middlewares-fast-route)[middlewares/client-ip

Middleware to detect the client ip and save it as a request attribute

16629.7k9](/packages/middlewares-client-ip)[middlewares/negotiation

Middleware to implement content negotiation

47442.1k11](/packages/middlewares-negotiation)[middlewares/payload

Middleware to parse the body of the request with support for json, csv and url-encode

32466.8k17](/packages/middlewares-payload)[middlewares/http-authentication

Middleware to implement Basic and Digest Http authentication

35302.0k2](/packages/middlewares-http-authentication)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
