chrishardie/laravel-synced-ip-allowlist
Composer 安装命令:
composer require chrishardie/laravel-synced-ip-allowlist
包简介
A Laravel package that provides HTTP middleware to allow access from a centralized list of IPs
README 文档
README
A Laravel package that provides HTTP middleware to allow access from a centralized list of IPs
Installation
You can install the package via composer:
composer require chrishardie/laravel-synced-ip-allowlist
Set Up Variables
If you haven't already, generate an encryption key to use across all apps retrieving the list of IP addresses.
php artisan key:generate --show base64:...
Copy the key to a secure location and store it in the ALLOWED_IPS_KEY environment variable, see below.
Open .env and define these variables:
# The URL where the encrypted list of allowed IPs is publicized ALLOWED_IPS_URL="https://example.com/allowed-ips.txt" # Encryption key for securely publicizing the IP addresses allowed ALLOWED_IPS_KEY="base64:..." # An optional URL to redirect unauthorized users to ALLOWED_IPS_REDIRECT_URL="https://laravel.com/"
If you want to further change package behavior, you can optionally publish the config file with:
php artisan vendor:publish --tag="laravel-synced-ip-allowlist-config"
This is the contents of the published config file:
return [ // The URL where the encrypted list of IP addresses allowed in CIDR notation is available 'allowed_ips_url' => env('ALLOWED_IPS_URL', 'https://example.com/allowed-ips.txt'), // The encryption key for encrypting and decrypting the list of IP addresses 'allowed_ips_key' => env('ALLOWED_IPS_KEY', env('APP_KEY')), // The cache key used to store the list of allowed IP addresses 'allowed_ips_cache_key' => 'allowed-ips.cidrs', // An optional URL to redirect unauthorized users to instead of showing a 403 error 'unauthorized_redirect_url' => env('ALLOWED_IPS_REDIRECT_URL'), ];
Usage
Encrypting and Publicizing Allowed IPs
Encrypt your list of IP addresses:
php artisan ip-allowlist:encrypt
Paste or type in the list of IPs and get the encrypted result:
Enter allowed IPs/ranges (one per line). Finish input with CTRL+D (Linux/macOS) or CTRL+Z (Windows):
# My first IP
12.34.56.78/32
# My second IP
98.76.54.32/32
Encrypted IP list:
eyJpd...
Take the encrypted result and put it at a URL that will be accessible to the applications using this package, e.g. https://example.com/allowed-ips.txt
Run Initial Sync
php artisan ip-allowlist:sync
Result:
Fetching IP list from https://example.com/allowed-ips.txt
Cached 2 CIDRs.
Future Syncs are Scheduled
The sync process will run twice daily:
$ php artisan schedule:list | grep ip-allowlist 0 1,13 * * * php artisan ip-allowlist:sync ..... Next Due: 11 hours from now
Use the Middleware to Protect a Route
In bootstrap/app.php, create or add to the list of available middleware aliases:
... ->withMiddleware(function (Middleware $middleware) { $middleware->alias([ 'allowed-ips' => \ChrisHardie\SyncedIpAllowlist\Http\Middleware\RestrictByAllowedIps::class, ]); }) ...
Or, for older versions of Laravel, in app/Http/Kernel.php, add an entry to the list of named, available HTTP route middleware:
protected $routeMiddleware = [ 'allowed-ips' => \ChrisHardie\SyncedIpAllowlist\Http\Middleware\RestrictByAllowedIps::class, ];
Then, in your routes file routes/web.php:
Route::middleware(['allowed-ips'])->group(function () { // Protected routes Route::get(...); Route::post(...); });
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Credits
License
The MIT License (MIT). Please see License File for more information.
chrishardie/laravel-synced-ip-allowlist 适用场景与选型建议
chrishardie/laravel-synced-ip-allowlist 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 15 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 06 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「Chris Hardie」 「laravel-synced-ip-allowlist」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 chrishardie/laravel-synced-ip-allowlist 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 chrishardie/laravel-synced-ip-allowlist 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 chrishardie/laravel-synced-ip-allowlist 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Laravel package that provides a simple facade to the USPS Addresses API
Combine the power of Laravel Pulse with Spatie's Health Checks
Provides an interface to Athena EHR's API
Alfabank REST API integration
Oracle HCM Laravel SDK
Provides user level tenant tokens / scoped search keys.
统计信息
- 总下载量: 15
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-06-01