Skip to content

Trusted ingress

mozrin edited this page Nov 22, 2026 · 2 revisions

Trusted ingress

Cloudflare headers are useful only when the application can establish where they came from. A visitor can submit a header named CF-IPCountry to an exposed origin; the name alone establishes no trust.

Current trust contract

The 0.9.0 package compares the connection's REMOTE_ADDR against cloudflare.trusted_proxies. Each entry must be an IPv4/IPv6 address or CIDR. The default list is empty. Wildcards are unsupported and invalid entries are ignored.

When no configured entry matches, visitor metadata remains null and request context reports trusted = false. An accepted immediate peer produces trusted = true, even when Cloudflare metadata is absent. This flag describes accepted ingress; it does not authenticate a visitor or establish that every Cloudflare product is available.

Direct Cloudflare-to-origin connections

For a direct connection, the immediate peer is normally a Cloudflare edge address. Configure the applicable official Cloudflare ranges and apply the appropriate origin restrictions for your deployment.

Public Cloudflare ranges are shared infrastructure; accepting them alone is not proof of your specific zone's identity. Establish the required provenance at ingress and prevent arbitrary direct-origin traffic or untrusted intermediate proxies from supplying accepted headers.

The current package does not automatically download, refresh or activate public IP lists.

Cloudflare Tunnel and additional proxy hops

With Tunnel, a local cloudflared connector or another internal proxy may be the immediate peer reaching Laravel. Public Cloudflare edge ranges do not identify that local connection.

Configure the actual controlled peer and make sure its reachable ingress paths cannot introduce unverified Cloudflare metadata. Do not broadly trust all private networks merely to populate the visitor panel. A peer address identifies a hop; your topology must establish the headers' provenance.

Moztopia Cloudflare consumes requests delivered by an existing Tunnel. It does not need Tunnel account credentials and does not create, run or delete tunnels.

Keep Laravel proxy configuration separate

The package does not modify Laravel's TrustProxies middleware or automatically reuse its trusted-proxy list. Laravel may trust a load balancer for URL generation without that balancer establishing Cloudflare-specific header provenance.

Configure Laravel's forwarded URL/IP handling separately when required. The package's parsed scheme property does not itself make Laravel generate HTTPS URLs or change request()->ip().

If a web server rewrites REMOTE_ADDR to the visitor's IP, the original peer is no longer available to the current package check. Preserve an independently verifiable ingress peer in your deployment design; do not compensate by trusting visitor addresses or arbitrary request headers.

Location settings

Cloudflare IP Geolocation supplies CF-IPCountry. The Add visitor location headers Managed Transform supplies the additional location headers. Missing data can result from settings, unavailable geolocation or intermediary behavior. The package cannot infer a disabled Cloudflare product from a missing header.

Unreleased expanded trust and isolation verification

Source 13a6099c7352189b24808ab7b78a78c78f212daf, tracked by #22 and PR #56, adds regression coverage toward 0.10.0 Cirrus without changing the existing runtime policy. The canonical configuration and explicit-empty precedence also apply to the expanded snapshots and diagnostics.

The verified matrix checks exact IPv4/IPv6 addresses, CIDR lower/upper and host boundaries, mixed families, malformed peers/configuration, and IPv4-mapped IPv6 behavior in the resolved Symfony versions. Forwarded headers, True-Client-IP, X-Real-IP and CF-Connecting-IP cannot turn an unrelated raw peer into accepted ingress, even when Laravel uses forwarded IP/scheme information. The package neither changes nor inherits Laravel's trusted-proxy configuration.

An operator-supplied 0.0.0.0/0 or ::/0 remains an accepted CIDR under the existing explicit policy, but accepts arbitrary peers in that family. It is unsafe for establishing controlled ingress. Diagnostics and doctor report unrestricted_trust, and the doctor exits with failure. Use a deliberately controlled perimeter instead; no broad list is installed automatically. Invalid list entries do not invalidate a separate valid matching entry; an invalid canonical list does not fall back to legacy trust.

Tests demonstrate both sides of the rewritten-peer limitation: a legitimate original proxy can become unrecognized after REMOTE_ADDR is rewritten, and any value already rewritten to a configured peer is indistinguishable from that peer. Client-supplied header values can likewise parse when a trusted proxy forwards them unchanged. The package cannot repair either loss of provenance. Require the ingress to overwrite or remove those headers and prevent uncontrolled paths before enabling trust.

Read visitor(), requestContext() and diagnostics() within the current request. Each result is an immutable snapshot; retaining it deliberately retains the earlier request's data. Do not store a visitor snapshot in an application singleton, shared cache or global variable. The package service retains no visitor/configuration snapshot and resolves the active container for each read. Fixtures are independent data; constructing one never applies its headers or changes live trust.

Sequential regression tests warm the real service/facade, then drive three rounds of eight trusted/missing/malformed/untrusted/disabled/invalid/zero-coordinate cases through both Laravel's HTTP kernel and the actual Octane Worker. All ten visitor properties, request context, twelve diagnostic header states, Blade output, old snapshots and fixture immutability are checked. Octane's native configuration sandbox/reset listeners run, including recovery after a failing request; kernel tests restore intentional test configuration changes explicitly.

Only the Octane application factory and transport are adapted to the booted Testbench application. This verifies the in-process Worker lifecycle, not RoadRunner/Swoole/FrankenPHP binaries, network transports, parallel coroutines or every custom listener configuration. Octane is development-only and is not required in a consuming application. Development and verification gives commands and evidence. Controlled live Cloudflare validation remains a separate gate.

Personalization and caches

If Laravel renders a country-dependent page, ensure full-page/CDN caches bypass that personalized response or use a deliberately configured cache key that matches the decision. A Blade conditional does not create a separate Cloudflare cache entry.

A response served entirely from the edge does not execute Laravel. The package cannot observe every cached visitor or report the final edge-cache result from an incoming origin request.

References: package trust implementation, Cloudflare request headers, managed location headers.

Maintained by-dolly.

Clone this wiki locally