From d0b50fec143dee5572c814cc8dbbf6eb8ddc6400 Mon Sep 17 00:00:00 2001 From: Alexis Saettler Date: Sun, 14 Aug 2022 00:01:22 +0200 Subject: [PATCH] fix: fix laravel cloudflare proxy (#6264) --- app/Http/Middleware/TrustProxies.php | 2 +- app/Providers/AppServiceProvider.php | 6 - composer.lock | 22 ++-- config/app.php | 10 -- config/debugbar.php | 170 --------------------------- config/laravelcloudflare.php | 62 ++++++++++ phpunit.xml | 1 + 7 files changed, 75 insertions(+), 198 deletions(-) delete mode 100644 config/debugbar.php create mode 100644 config/laravelcloudflare.php diff --git a/app/Http/Middleware/TrustProxies.php b/app/Http/Middleware/TrustProxies.php index 1cd524541..f88f21339 100644 --- a/app/Http/Middleware/TrustProxies.php +++ b/app/Http/Middleware/TrustProxies.php @@ -13,6 +13,6 @@ class TrustProxies extends Middleware */ protected function proxies() { - return config('app.trust_proxies'); + return config('app.trust_proxies') ?? $this->proxies; } } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 1094a6d44..76604afcd 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -15,12 +15,10 @@ use Illuminate\Support\Facades\Schema; use Illuminate\Support\ServiceProvider; use Illuminate\Cache\RateLimiting\Limit; use Illuminate\Validation\Rules\Password; -use Monicahq\Cloudflare\LaravelCloudflare; use Illuminate\Support\Facades\RateLimiter; use Illuminate\Auth\Notifications\VerifyEmail; use Werk365\EtagConditionals\EtagConditionals; use Illuminate\Auth\Notifications\ResetPassword; -use Monicahq\Cloudflare\Facades\CloudflareProxies; class AppServiceProvider extends ServiceProvider { @@ -114,10 +112,6 @@ class AppServiceProvider extends ServiceProvider return sha1($url); }); }); - - LaravelCloudflare::getProxiesUsing(function (): array { - return config('app.cloudflare') ? CloudflareProxies::load() : []; - }); } /** diff --git a/composer.lock b/composer.lock index c5ade112e..e7d0dedde 100644 --- a/composer.lock +++ b/composer.lock @@ -218,16 +218,16 @@ }, { "name": "aws/aws-sdk-php", - "version": "3.233.0", + "version": "3.233.1", "source": { "type": "git", "url": "https://github.com/aws/aws-sdk-php.git", - "reference": "2aabbc276b61515ae1897f037fc34ad56028d744" + "reference": "1eeac24f921f146b7cef5beb61375d7852df7cf8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/2aabbc276b61515ae1897f037fc34ad56028d744", - "reference": "2aabbc276b61515ae1897f037fc34ad56028d744", + "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/1eeac24f921f146b7cef5beb61375d7852df7cf8", + "reference": "1eeac24f921f146b7cef5beb61375d7852df7cf8", "shasum": "" }, "require": { @@ -304,9 +304,9 @@ "support": { "forum": "https://forums.aws.amazon.com/forum.jspa?forumID=80", "issues": "https://github.com/aws/aws-sdk-php/issues", - "source": "https://github.com/aws/aws-sdk-php/tree/3.233.0" + "source": "https://github.com/aws/aws-sdk-php/tree/3.233.1" }, - "time": "2022-08-11T18:15:54+00:00" + "time": "2022-08-12T18:18:34+00:00" }, { "name": "bacon/bacon-qr-code", @@ -4708,16 +4708,16 @@ }, { "name": "monicahq/laravel-cloudflare", - "version": "3.2.2", + "version": "3.3.0", "source": { "type": "git", "url": "https://github.com/monicahq/laravel-cloudflare.git", - "reference": "bc8881e04223bdd1c564fdfcdc09f11c443e917d" + "reference": "80318641a7a85bf29e6c24cf850309bb12df1486" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/monicahq/laravel-cloudflare/zipball/bc8881e04223bdd1c564fdfcdc09f11c443e917d", - "reference": "bc8881e04223bdd1c564fdfcdc09f11c443e917d", + "url": "https://api.github.com/repos/monicahq/laravel-cloudflare/zipball/80318641a7a85bf29e6c24cf850309bb12df1486", + "reference": "80318641a7a85bf29e6c24cf850309bb12df1486", "shasum": "" }, "require": { @@ -4780,7 +4780,7 @@ "type": "github" } ], - "time": "2022-01-30T15:22:48+00:00" + "time": "2022-08-13T21:35:05+00:00" }, { "name": "monicahq/laravel-sabre", diff --git a/config/app.php b/config/app.php index 5304ce5d5..523c28e8b 100644 --- a/config/app.php +++ b/config/app.php @@ -151,16 +151,6 @@ return [ 'trust_proxies' => env('APP_TRUSTED_PROXIES', env('APP_TRUST_PROXIES')), - /* - |-------------------------------------------------------------------------- - | Enable cloudflare trusted proxies - |-------------------------------------------------------------------------- - | - | Enable to trust cloudflare proxies. - | - */ - 'cloudflare' => (bool) env('APP_TRUSTED_CLOUDFLARE', false), - /* |-------------------------------------------------------------------------- | Autoloaded Service Providers diff --git a/config/debugbar.php b/config/debugbar.php deleted file mode 100644 index e4cf47738..000000000 --- a/config/debugbar.php +++ /dev/null @@ -1,170 +0,0 @@ - null, - - /* - |-------------------------------------------------------------------------- - | Storage settings - |-------------------------------------------------------------------------- - | - | DebugBar stores data for session/ajax requests. - | You can disable this, so the debugbar stores data in headers/session, - | but this can cause problems with large data collectors. - | By default, file storage (in the storage folder) is used. Redis and PDO - | can also be used. For PDO, run the package migrations first. - | - */ - 'storage' => [ - 'enabled' => true, - 'driver' => 'file', // redis, file, pdo, custom - 'path' => storage_path('debugbar'), // For file driver - 'connection' => null, // Leave null for default connection (Redis/PDO) - 'provider' => '', // Instance of StorageInterface for custom driver - ], - - /* - |-------------------------------------------------------------------------- - | Vendors - |-------------------------------------------------------------------------- - | - | Vendor files are included by default, but can be set to false. - | This can also be set to 'js' or 'css', to only include javascript or css vendor files. - | Vendor files are for css: font-awesome (including fonts) and highlight.js (css files) - | and for js: jquery and and highlight.js - | So if you want syntax highlighting, set it to true. - | jQuery is set to not conflict with existing jQuery scripts. - | - */ - - 'include_vendors' => true, - - /* - |-------------------------------------------------------------------------- - | Capture Ajax Requests - |-------------------------------------------------------------------------- - | - | The Debugbar can capture Ajax requests and display them. If you don't want this (ie. because of errors), - | you can use this option to disable sending the data through the headers. - | - */ - - 'capture_ajax' => true, - - /* - |-------------------------------------------------------------------------- - | Clockwork integration - |-------------------------------------------------------------------------- - | - | The Debugbar can emulate the Clockwork headers, so you can use the Chrome - | Extension, without the server-side code. It uses Debugbar collectors instead. - | - */ - 'clockwork' => false, - - /* - |-------------------------------------------------------------------------- - | DataCollectors - |-------------------------------------------------------------------------- - | - | Enable/disable DataCollectors - | - */ - - 'collectors' => [ - 'phpinfo' => true, // Php version - 'messages' => true, // Messages - 'time' => true, // Time Datalogger - 'memory' => true, // Memory usage - 'exceptions' => true, // Exception displayer - 'log' => false, // Logs from Monolog (merged in messages if enabled) - 'db' => true, // Show database (PDO) queries and bindings - 'views' => true, // Views with their data - 'route' => true, // Current route information - 'laravel' => false, // Laravel version and environment - 'events' => false, // All events fired - 'default_request' => false, // Regular or special Symfony request logger - 'symfony_request' => true, // Only one can be enabled.. - 'mail' => true, // Catch mail messages - 'logs' => false, // Add the latest log messages - 'files' => false, // Show the included files - 'config' => false, // Display config settings - 'auth' => false, // Display Laravel authentication status - 'gate' => false, // Display Laravel Gate checks - 'session' => true, // Display session data - ], - - /* - |-------------------------------------------------------------------------- - | Extra options - |-------------------------------------------------------------------------- - | - | Configure some DataCollectors - | - */ - - 'options' => [ - 'auth' => [ - 'show_name' => false, // Also show the users name/email in the debugbar - ], - 'db' => [ - 'with_params' => true, // Render SQL with the parameters substituted - 'timeline' => false, // Add the queries to the timeline - 'backtrace' => false, // EXPERIMENTAL: Use a backtrace to find the origin of the query in your files. - 'explain' => [ // EXPERIMENTAL: Show EXPLAIN output on queries - 'enabled' => false, - 'types' => ['SELECT'], // ['SELECT', 'INSERT', 'UPDATE', 'DELETE']; for MySQL 5.6.3+ - ], - 'hints' => true, // Show hints for common mistakes - ], - 'mail' => [ - 'full_log' => false, - ], - 'views' => [ - 'data' => false, //Note: Can slow down the application, because the data can be quite large.. - ], - 'route' => [ - 'label' => true, // show complete route on bar - ], - 'logs' => [ - 'file' => null, - ], - ], - - /* - |-------------------------------------------------------------------------- - | Inject Debugbar in Response - |-------------------------------------------------------------------------- - | - | Usually, the debugbar is added just before , by listening to the - | Response after the App is done. If you disable this, you have to add them - | in your template yourself. See http://phpdebugbar.com/docs/rendering.html - | - */ - - 'inject' => true, - - /* - |-------------------------------------------------------------------------- - | DebugBar route prefix - |-------------------------------------------------------------------------- - | - | Sometimes you want to set route prefix to be used by DebugBar to load - | its resources from. Usually the need comes from misconfigured web server or - | from trying to overcome bugs like this: http://trac.nginx.org/nginx/ticket/97 - | - */ - 'route_prefix' => '_debugbar', - -]; diff --git a/config/laravelcloudflare.php b/config/laravelcloudflare.php new file mode 100644 index 000000000..7770d1908 --- /dev/null +++ b/config/laravelcloudflare.php @@ -0,0 +1,62 @@ + (bool) env('LARAVEL_CLOUDFLARE_ENABLED', env('APP_TRUSTED_CLOUDFLARE', false)), + + /* + |-------------------------------------------------------------------------- + | Name of the cache to store values of the proxies + |-------------------------------------------------------------------------- + | + | This value is the key used in the cache (table, redis, etc.) to store the + | values. + | + */ + + 'cache' => 'cloudflare.proxies', + + /* + |-------------------------------------------------------------------------- + | Cloudflare main url + |-------------------------------------------------------------------------- + | + | This is the url for the cloudflare api. + | + */ + + 'url' => 'https://www.cloudflare.com', + + /* + |-------------------------------------------------------------------------- + | Cloudflare uri for ipv4 ips response + |-------------------------------------------------------------------------- + | + | This is the path to get the values of ipv4 ips from Cloudflare. + | + */ + + 'ipv4-path' => 'ips-v4', + + /* + |-------------------------------------------------------------------------- + | Cloudflare uri for ipv6 ips response + |-------------------------------------------------------------------------- + | + | This is the path to get the values of ipv6 ips from Cloudflare. + | + */ + + 'ipv6-path' => 'ips-v6', + +]; diff --git a/phpunit.xml b/phpunit.xml index 65edbea65..f34d3b084 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -72,5 +72,6 @@ +