Search by

hosni / laravel-edge-trust

hosni

Automatically manage trusted proxy IP ranges for Laravel applications.

Package info

github.com/hosni/laravel-edge-trust

pkg:composer/hosni/laravel-edge-trust

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

0.1.0 2026-06-25 13:30 UTC

This package is auto-updated.

Last update: 2026-12-04 06:43:19 UTC


README

Build Status PHPStan Latest Version License: MIT PHP Version

Automatically manage trusted proxy IP ranges for Laravel applications.

EdgeTrust keeps your TrustProxies middleware aligned with real CDN / edge network address ranges. It ships verified bundled archives, can refresh them on a schedule into cache, and never performs HTTP on the request path.

Features

  • Built-in providers: Cloudflare, AWS CloudFront, Fastly, Bunny CDN, Google Cloud (goog.json), ArvanCloud
  • Modes: bundled · runtime · hybrid (recommended)
  • Atomic sync with validation, non-global rejection, duplicate detection, min-prefix and max-change safeguards
  • Runtime cache with stale / last-known-good fallback (array, file, redis, database, …)
  • Artisan commands for sync, status, validation, and listing
  • Extensible custom providers via EdgeTrust::registerProvider()
  • PHPStan level 8, Pint, Pest + Orchestra Testbench

Requirements

  • PHP 8.2+
  • Laravel 10+, 11, 12, or 13

Installation

composer require hosni/laravel-edge-trust

Publishing config is optional — most apps only need .env:

EDGE_TRUST_MODE=hybrid
EDGE_TRUST_PROVIDERS=cloudflare
# EDGE_TRUST_PROVIDERS=cloudflare,aws_cloudfront,fastly
# EDGE_TRUST_PROVIDERS=*   # every registered provider
# optional — only if you need nested validation / custom provider classes
php artisan vendor:publish --tag=edge-trust-config

Quick start

Replace your application TrustProxies middleware with EdgeTrust’s (do not silently stack both):

// bootstrap/app.php — Laravel 11+
->withMiddleware(function (Middleware $middleware) {
    $middleware->trustProxies(at: \Hosni\EdgeTrust\Facades\EdgeTrust::proxies());
})
// app/Http/Kernel.php — Laravel 10
protected $middleware = [
    \Hosni\EdgeTrust\Http\Middleware\TrustProxies::class,
    // ...
];

Laravel 9 and below are outside the supported constraint range (^10.0). See the Trust Proxies guide for full examples.

Schedule refreshes (registered automatically when sync.schedule is true):

php artisan edge-trust:sync

Modes

Mode Behaviour
bundled Package archives only — no HTTP
runtime Provider fetch into cache (via sync / scheduler), never per-request
hybrid Fresh runtime → last known good → bundled

Per-provider source overrides: bundled, provider, registry, custom.

Commands

php artisan edge-trust:sync [--provider=] [--force]
php artisan edge-trust:update [--provider=] [--force]   # alias of sync
php artisan edge-trust:providers
php artisan edge-trust:status [--provider=] [--json]
php artisan edge-trust:validate [--provider=] [--json]
php artisan edge-trust:list [--provider=] [--json]
php artisan edge-trust:clear [--provider=] [--force]

Exit codes: 0 success, 1 failure, 2 when all syncs were skipped (lock contention).

Custom providers

use Hosni\EdgeTrust\Facades\EdgeTrust;
use App\EdgeTrust\MyCustomProxyProvider;

EdgeTrust::registerProvider('my-proxy', MyCustomProxyProvider::class);

Implement Hosni\EdgeTrust\Contracts\ProxyProvider or extend AbstractProvider.

Provider notes

Key Official source Notes
cloudflare cloudflare.com/ips-v4 · ips-v6 Plain CIDR lines
aws_cloudfront ip-ranges.amazonaws.com Filtered to service === CLOUDFRONT
fastly api.fastly.com/public-ip-list addresses + ipv6_addresses
bunny bunnycdn.com edgeserverlist Hosts converted to /32 / /128
google_cloud gstatic.com/ipranges/goog.json Google-owned frontend ranges; broader than Cloud CDN-only
arvancloud arvancloud.ir/fa/ips.txt Display name ArvanCloud

Regenerating bundled archives

composer update-archives
# or with CI artifacts:
php bin/update-archives.php --summary-dir=/tmp/edge-trust-summary
# offline from cached downloads (same provider parsers via Http fake):
php bin/update-archives.php --from-cache=/tmp --summary-dir=/tmp/edge-trust-summary

The Symfony Console command reuses package providers (no duplicated parsers) and writes summary.json, commit-message.txt, release-notes.md, and changelog-entry.md for CI.

Archives live in resources/proxies/*.json with manifest.json (schema version, SHA-256 checksums, counts).

Testing & quality

composer test
composer analyse
composer format

Security

  • Invalid / partial sync payloads are never cached
  • Concurrent syncs are lock-guarded to prevent stampedes
  • On validation or threshold failure, previous valid data is retained
  • Public CDN sources reject non-global ranges by default

License

MIT — see LICENSE.