Skip to content

Commit

Permalink
Allow to set APP_CLOUDFLARE_IS_USED=true for proper client IP detecti…
Browse files Browse the repository at this point in the history
…on when CloudFlare is used - closes #3467
  • Loading branch information
freescout-help-desk committed Oct 23, 2023
1 parent ccb8658 commit 7708fa8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
7 changes: 7 additions & 0 deletions config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,13 @@
'csp_enabled' => env('APP_CSP_ENABLED', true),
'csp_script_src' => env('APP_CSP_SCRIPT_SRC', ''),

/*
|--------------------------------------------------------------------------
| Let the application know that CloudFlare is used (for proper client IP detection).
|-------------------------------------------------------------------------
*/
'cloudflare_is_used' => env('APP_CLOUDFLARE_IS_USED', false),

/*
|--------------------------------------------------------------------------
| Autoloaded Service Providers
Expand Down
9 changes: 9 additions & 0 deletions overrides/symfony/http-foundation/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,15 @@ public function setSession(SessionInterface $session)
*/
public function getClientIps()
{
// Fix for CloudFlare.
if (isset($_SERVER["HTTP_CF_CONNECTING_IP"])
&& $_SERVER['REMOTE_ADDR'] != $_SERVER["HTTP_CF_CONNECTING_IP"]
&& config('app.cloudflare_is_used')
) {
$_SERVER['REMOTE_ADDR'] = $_SERVER["HTTP_CF_CONNECTING_IP"];
$this->server->set('REMOTE_ADDR', $_SERVER["HTTP_CF_CONNECTING_IP"]);
}

$ip = $this->server->get('REMOTE_ADDR');

if (!$this->isFromTrustedProxy()) {
Expand Down

0 comments on commit 7708fa8

Please sign in to comment.