Skip to content

Commit c7d48d7

Browse files
authored
Merge pull request pterodactyl#284 from Pterodactyl/fix/trusted-proxies
Allow to set trusted proxies to allow usage of load balancers and reverse proxies
2 parents 8cac2a3 + 19567ee commit c7d48d7

File tree

4 files changed

+64
-0
lines changed

4 files changed

+64
-0
lines changed

app/Http/Kernel.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ class Kernel extends HttpKernel
1717
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
1818
\Illuminate\Session\Middleware\StartSession::class,
1919
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
20+
2021
\Pterodactyl\Http\Middleware\LanguageMiddleware::class,
22+
\Fideloper\Proxy\TrustProxies::class,
2123
];
2224

2325
/**

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"dingo/api": "1.0.0-beta6",
2828
"aws/aws-sdk-php": "3.19.20",
2929
"predis/predis": "1.1.1",
30+
"fideloper/proxy": "3.2.0",
3031
"laracasts/utilities": "2.1.0",
3132
"lord/laroute": "2.3.0"
3233
},

config/app.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@
160160
igaster\laravelTheme\themeServiceProvider::class,
161161
Prologue\Alerts\AlertsServiceProvider::class,
162162
Krucas\Settings\Providers\SettingsServiceProvider::class,
163+
Fideloper\Proxy\TrustedProxyServiceProvider::class,
163164
Laracasts\Utilities\JavaScript\JavaScriptServiceProvider::class,
164165
Lord\Laroute\LarouteServiceProvider::class,
165166

config/trustedproxy.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
return [
4+
5+
/*
6+
* Set trusted proxy IP addresses.
7+
*
8+
* Both IPv4 and IPv6 addresses are
9+
* supported, along with CIDR notation.
10+
*
11+
* The "*" character is syntactic sugar
12+
* within TrustedProxy to trust any proxy
13+
* that connects directly to your server,
14+
* a requirement when you cannot know the address
15+
* of your proxy (e.g. if using Rackspace balancers).
16+
*
17+
* The "**" character is syntactic sugar within
18+
* TrustedProxy to trust not just any proxy that
19+
* connects directly to your server, but also
20+
* proxies that connect to those proxies, and all
21+
* the way back until you reach the original source
22+
* IP. It will mean that $request->getClientIp()
23+
* always gets the originating client IP, no matter
24+
* how many proxies that client's request has
25+
* subsequently passed through.
26+
*/
27+
'proxies' => in_array(env('TRUSTED_PROXIES', ['*', '**'])) ?
28+
env('TRUSTED_PROXIES') : explode(',', env('TRUSTED_PROXIES', null)),
29+
30+
/*
31+
* Or, to trust all proxies that connect
32+
* directly to your server, uncomment this:
33+
*/
34+
// 'proxies' => '*',
35+
36+
/*
37+
* Or, to trust ALL proxies, including those that
38+
* are in a chain of fowarding, uncomment this:
39+
*/
40+
// 'proxies' => '**',
41+
42+
/*
43+
* Default Header Names
44+
*
45+
* Change these if the proxy does
46+
* not send the default header names.
47+
*
48+
* Note that headers such as X-Forwarded-For
49+
* are transformed to HTTP_X_FORWARDED_FOR format.
50+
*
51+
* The following are Symfony defaults, found in
52+
* \Symfony\Component\HttpFoundation\Request::$trustedHeaders
53+
*/
54+
'headers' => [
55+
\Illuminate\Http\Request::HEADER_CLIENT_IP => 'X_FORWARDED_FOR',
56+
\Illuminate\Http\Request::HEADER_CLIENT_HOST => 'X_FORWARDED_HOST',
57+
\Illuminate\Http\Request::HEADER_CLIENT_PROTO => 'X_FORWARDED_PROTO',
58+
\Illuminate\Http\Request::HEADER_CLIENT_PORT => 'X_FORWARDED_PORT',
59+
],
60+
];

0 commit comments

Comments
 (0)