Skip to content

Commit

Permalink
fix: support configuring trusted proxies
Browse files Browse the repository at this point in the history
Fixes #569.

Allows users to configure TRUSTED_PROXIES to get the correct IP
addresses reported based on the proxy forwarding headers.
  • Loading branch information
thor committed Sep 16, 2023
1 parent c47a02b commit 7d87a6c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions CONFIGURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Table with all the variables, default value and explanation. Override the enviro
| MAIL_ENCRYPTION | null | Mail encryption |
| MAIL_FROM_NAME | Control Center | Mail from name |
| MAIL_FROM_ADDRESS | [email protected] | Mail from address |
| TRUSTED_PROXIES | null | Comma-separated list of trusted proxy addresses or '*' for all |

#### OAuth

Expand Down
10 changes: 9 additions & 1 deletion app/Http/Middleware/TrustProxies.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ class TrustProxies extends Middleware
*
* @var array
*/
protected $proxies;
public function proxies(): null|string|array
{
$trusted = config('app.proxies.trusted');
if ($trusted != null && str_contains($trusted, ',')) {
return explode(',', $trusted);
}

return $trusted;
}

/**
* The headers that should be used to detect proxies.
Expand Down
13 changes: 13 additions & 0 deletions config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,19 @@

],

/*
|--------------------------------------------------------------------------
| Network & Requests
|--------------------------------------------------------------------------
| Configure the list of proxies that you trust if you are running Control
| Center behind a proxy such as nginx, traefik or similarly.
| Separate allowed proxies with a comma (no space!).
| If you're running Control Center in a container, you may set it to '*'.
*/
'proxies' => [
'trusted' => env('TRUSTED_PROXIES'),
],

/*
|--------------------------------------------------------------------------
| Class Aliases
Expand Down

0 comments on commit 7d87a6c

Please sign in to comment.