laravel-cloudflare
laravel-cloudflare copied to clipboard
User Configured Trusted Proxy Gets Ignored
My best guess is because in the following code, the parent will get called after the merge with $this->proxy. This issue will happen, and user-configured proxies will never be used. https://github.com/monicahq/laravel-cloudflare/blob/7889d03f8a2939df82f5a85451c9dabf54bee267/src/Http/Middleware/TrustProxies.php#L41-L61
- Note: I'm using Laravel Octane.
I found out that if the proxy variable is set, the config('trustedproxy.proxies') will be ignored by Laravel. Feel free to close the issue if this is the default behavior
It's because this package's setTrustedProxyCloudflare method will set the $alwaysTrustProxies static array on the parent TrustProxies middleware. This static array always gets priority over the $proxies set: https://github.com/laravel/framework/blob/12.x/src/Illuminate/Http/Middleware/TrustProxies.php#L165-L168
The easiest fix would be to inject your custom proxies into the getProxiesUsing callback:
LaravelCloudflare::getProxiesUsing(function() {
return array_merge(
CloudflareProxies::load(),
config('trustedproxy.proxies', [])
);
});
Or extending the TrustProxies middleware and just hacking your own proxies in there by overriding one of the methods there.