PHPackages                             jundayw/laravel-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. [Security](/categories/security)
4. /
5. jundayw/laravel-firewall

ActiveLibrary[Security](/categories/security)

jundayw/laravel-firewall
========================

A Laravel firewall whitelisting and blacklisting

v0.1.0.0616\_beta(3y ago)05MITPHPPHP &gt;=7.2.0

Since Jun 16Pushed 3y ago1 watchersCompare

[ Source](https://github.com/jundayw/laravel-firewall)[ Packagist](https://packagist.org/packages/jundayw/laravel-firewall)[ RSS](/packages/jundayw-laravel-firewall/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (2)Versions (2)Used By (0)

Installation
============

[](#installation)

Compatible with
---------------

[](#compatible-with)

- Laravel 5.5+

Installing
----------

[](#installing)

```
composer require jundayw/laravel-firewall

```

这个包使用包 Auto-Discovery's 特性，并且应该在您通过 Composer 安装它后立即可用。 并且预置三个中间件，方便直接调用：

```
protected $routeMiddleware = [
    ...
    'firewall.black' => \Jundayw\LaravelFirewall\Middleware\FirewallBlacklist::class,
    'firewall.white' => \Jundayw\LaravelFirewall\Middleware\FirewallWhitelist::class,
    'firewall.attacks' => \Jundayw\LaravelFirewall\Middleware\FirewallBlockAttacks::class,
];

```

然后您可以在路由中使用它们：

```
Route::group(['middleware' => 'firewall.attacks'], function () {
    Route::get('/', 'HomeController@index');
});

```

发布配置文件：

```
php artisan vendor:publish --tag=firewall-config

```

发布IP数据库文件：

```
php artisan vendor:publish --tag=firewall-country

```

> 如果需要，您可以手动更新 `GeoLite2-Country.mmdb` 数据库文件。[MaxMind-DB](https://github.com/maxmind/MaxMind-DB)

Purpose
=======

[](#purpose)

这是一个软防火墙包。 它的目的是帮助人们防止未经授权访问IP地址的路由。它能够跟踪IP、国家和主机（动态IP），同时允许白名单IP访问整个站点。 它现在还能够检测和阻止来自单个IP或整个国家的攻击（太多请求）。

这个软件包可以防止一些麻烦，帮助你阻止对你的应用程序的访问， 但不能取代防火墙和设备，对于网络级别的攻击，你仍然需要一个真正的防火墙。

Features
========

[](#features)

- 通过黑名单和白名单控制访问。
- 检测并阻止来自IP地址或国家/地区的应用程序攻击
- 使用中间件完成，因此您可以保护/取消保护路由组
- 所有功能都可用于主机、IP地址、IP地址范围和整个国家
- 每次请求增加不到10ms

Concepts
========

[](#concepts)

Firewall 包含 `Blacklist` 及 `Whitelist` ， AttackBlocker 包含 `rate_limiter`。

Blacklist
---------

[](#blacklist)

这些列表中的所有IP地址将无法访问由黑名单筛选器筛选的路由。

Whitelist
---------

[](#whitelist)

这些IP地址、范围或国家可以

- 访问黑名单路由，即使它们在黑名单IP地址范围内
- 访问“允许白名单”筛选路由

AttackBlocker
-------------

[](#attackblocker)

- 可锚定 `Blacklist` ，共享黑名单限制范围
- 可锚定 `Whitelist` ，共享白名单限制范围
- 可限定 `rate_limiter` 中 `IP` 访问频率
- 可限定 `rate_limiter` 中 `country` 访问频率

IPs lists
=========

[](#ips-lists)

IPs（黑白）列表可以存储在数组、文件和数据库中。 因此，要测试防火墙配置，可以发布配置文件并编辑blacklist或whitelist数组：

```
'blacklist' => array(
    '127.0.0.1',
    '192.168.17.0/24',
    '127.0.0.1/255.255.255.255',
    '10.0.0.1-10.0.0.255',
    '172.17.*.*',
    'country:br',
    'host:www.baidu.com',
    '/usr/bin/firewall/blacklisted.txt',
),
```

文件（例如/usr/bin/firewall/blacklisted.txt）每行必须包含一个IP、范围或文件名， 而且，它将递归地搜索文件，因此，如果需要，您可以文件中包含一个文件：

```
127.0.0.2
10.0.0.0-10.0.0.100
/tmp/blacklist.txt

```

Artisan Commands
================

[](#artisan-commands)

```
php artisan firewall --list
+------------+-----------+-----------+
| ip_address | whitelist | blacklist |
+------------+-----------+-----------+
| 127.0.0.1  |           |     x     |
| 127.0.0.2  |           |     x     |
| country:us |     x     |           |
+------------+-----------+-----------+

php artisan firewall --reload

php artisan firewall:blacklist -l
php artisan firewall:blacklist -f
php artisan firewall:blacklist -d=country:cn
php artisan firewall:blacklist -a=127.0.0.1

php artisan firewall:whitelist --list
php artisan firewall:whitelist --flush
php artisan firewall:whitelist --delete=country:cn
php artisan firewall:whitelist --append=host:www.baidu.com

php artisan firewall:attack -l
php artisan firewall:attack -f
php artisan firewall:attack -d=country:cn
php artisan firewall:attack -a=10.0.0.0

```

Facade
======

[](#facade)

```
Firewall::isBlacklisted('127.0.0.1');
Firewall::isWhitelisted('127.0.0.1');
Firewall::isBlockAttacks('127.0.0.1');

```

###  Health Score

16

—

LowBetter than 5% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity28

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

1427d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2da9b458375a1b7972b7c4d26a5bf8f3e48db305e8805da36f253956f33c5568?d=identicon)[jundayw](/maintainers/jundayw)

---

Top Contributors

[![jundayw](https://avatars.githubusercontent.com/u/16873970?v=4)](https://github.com/jundayw "jundayw (1 commits)")

---

Tags

firewalllaravellaravelblacklistfirewallwhitelist

### Embed Badge

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

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

###  Alternatives

[pragmarx/firewall

A Laravel IP whitelisting and blacklisting

1.4k988.9k](/packages/pragmarx-firewall)[akaunting/laravel-firewall

Web Application Firewall (WAF) package for Laravel

999465.8k2](/packages/akaunting-laravel-firewall)

PHPackages © 2026

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