Download the PHP package robertboes/laravel-cloudflare-proxies without Composer

On this page you can find all versions of the php package robertboes/laravel-cloudflare-proxies. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-cloudflare-proxies

laravel-cloudflare-proxies

Trusts Cloudflare's published ranges and the private hop of your reverse proxy, and nothing else, so request()->ip() and request()->isSecure() are right behind Cloudflare, and a made-up X-Forwarded-For entry never wins.

That is the whole setup. If bootstrap/app.php calls trustProxies(at: ...), remove it: the package owns that setting, and php artisan cloudflare-proxies:check fails while the call is there.

How it works

Cloudflare and your proxy (Caddy, nginx, Traefik) each append to X-Forwarded-For. Laravel walks the header from the right, past the hops it trusts, and stops at the first one it does not: the address Cloudflare appended for the visitor. Anything the visitor sent sits to the left of that and is never reached.

This holds as long as:

  1. every trusted hop appends, and drops an incoming X-Forwarded-For from a peer it does not trust;
  2. only your own Cloudflare zones can reach the origin. Trusting Cloudflare's ranges trusts every Cloudflare customer, so restrict the origin with zone-level Authenticated Origin Pulls, not the shared certificate.

Nothing rewrites REMOTE_ADDR from CF-Connecting-IP: that collapses the chain and hides the proxy hop, which is how X-Forwarded-Proto ends up ignored.

Why not TRUSTED_PROXIES=*

On Laravel 13.20.0 and later, '*' trusts every hop, so the leftmost X-Forwarded-For entry wins and any visitor can choose their IP with one header. Before 13.20.0 it trusts only the calling hop, so behind a proxy every visitor resolves to a Cloudflare edge address.

Configuration

Publishing is optional; the defaults work as installed.

Key Default
enabled CLOUDFLARE_PROXIES_ENABLED, true Off leaves Laravel's own configuration in place.
cloudflare true Trust Cloudflare's ranges.
private true Trust 127.0.0.0/8, 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, ::1/128 and fc00::/7: a proxy on a Docker network.
proxies CLOUDFLARE_PROXIES_EXTRA Further hops, comma separated, such as a load balancer's range.
headers X-Forwarded-For, X-Forwarded-Proto A Request::HEADER_* bitmask.
refresh CLOUDFLARE_PROXIES_REFRESH, false See Keeping the ranges current.

private is deliberately narrower than Symfony's PRIVATE_SUBNETS, which also covers carrier-grade NAT (Tailscale), documentation ranges, and the Teredo and 6to4 tunnel ranges. Real clients live there, and trusting them lets a client spoof the walk.

X-Forwarded-Host and X-Forwarded-Port are not trusted: they carry a single value that a visitor can set and Laravel reads the leftmost one. Turn on $middleware->trustHosts() in bootstrap/app.php as well.

Proving it in your tests

Add the trait to your feature test case:

With PHPUnit, use the trait and call $this->expectCloudflareProxiesToWork().

The helper sends requests through your app's real middleware stack and checks that:

Checking a deployment

Prints the trusted ranges, whether trusted hosts and the runtime refresh are on, and what each sample request resolves to. It exits non-zero if the app overrides the package (trustProxies(at: ...), '*', trustedproxy.proxies, its own trusted headers), if TrustProxies is missing from the middleware stack, or if a sample request resolves wrongly. Run it in CI or on deploy.

Keeping the ranges current

The ranges ship with the package, in resources/cloudflare-ips.json. A daily job in this repository fetches Cloudflare's lists, and a change becomes a patch release, so Dependabot or Renovate is enough to stay current. No request ever fetches anything.

For an app that cannot wait for a release, turn on refresh and schedule the command:

The refresh validates every line, refuses empty, private, reserved or overly wide ranges (wider than /12 for IPv4 or /28 for IPv6), and stores the result in the default cache store. It can add ranges to the bundled snapshot, never remove them. A missing or broken cache means the snapshot alone. Octane and queue workers pick up a refresh when they restart.

License

MIT.


All versions of laravel-cloudflare-proxies with dependencies

PHP Build Version
Package Version
Requires php Version ^8.4
illuminate/console Version ^12.0|^13.0
illuminate/contracts Version ^12.0|^13.0
illuminate/http Version ^12.0|^13.0
illuminate/support Version ^12.0|^13.0
spatie/laravel-package-tools Version ^1.92
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package robertboes/laravel-cloudflare-proxies contains the following files

Loading the files please wait ...