Skip to content

Commit ee26a7e

Browse files
committed
add fideloper/proxy to support reverse proxies and load balancers
1 parent b5a7785 commit ee26a7e

File tree

5 files changed

+65
-1
lines changed

5 files changed

+65
-1
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ APP_CLEAR_TASKLOG=720
77
APP_DELETE_MINUTES=10
88
CONSOLE_PUSH_FREQ=250
99
CONSOLE_PUSH_COUNT=10
10+
TRUSTED_PROXIES=null
1011

1112
DB_HOST=localhost
1213
DB_PORT=3306

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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
"mtdowling/cron-expression": "1.1.0",
2727
"dingo/api": "1.0.0-beta6",
2828
"aws/aws-sdk-php": "3.19.20",
29-
"predis/predis": "1.1.1"
29+
"predis/predis": "1.1.1",
30+
"fideloper/proxy": "3.2.0"
3031
},
3132
"require-dev": {
3233
"fzaninotto/faker": "~1.4",

config/app.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@
158158
igaster\laravelTheme\themeServiceProvider::class,
159159
Prologue\Alerts\AlertsServiceProvider::class,
160160
Krucas\Settings\Providers\SettingsServiceProvider::class,
161+
Fideloper\Proxy\TrustedProxyServiceProvider::class,
161162

162163
],
163164

config/trustedproxy.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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' => explode(',', env('TRUSTED_PROXIES', null)),
28+
29+
/*
30+
* Or, to trust all proxies that connect
31+
* directly to your server, uncomment this:
32+
*/
33+
# 'proxies' => '*',
34+
35+
/*
36+
* Or, to trust ALL proxies, including those that
37+
* are in a chain of fowarding, uncomment this:
38+
*/
39+
# 'proxies' => '**',
40+
41+
/*
42+
* Default Header Names
43+
*
44+
* Change these if the proxy does
45+
* not send the default header names.
46+
*
47+
* Note that headers such as X-Forwarded-For
48+
* are transformed to HTTP_X_FORWARDED_FOR format.
49+
*
50+
* The following are Symfony defaults, found in
51+
* \Symfony\Component\HttpFoundation\Request::$trustedHeaders
52+
*/
53+
'headers' => [
54+
\Illuminate\Http\Request::HEADER_CLIENT_IP => 'X_FORWARDED_FOR',
55+
\Illuminate\Http\Request::HEADER_CLIENT_HOST => 'X_FORWARDED_HOST',
56+
\Illuminate\Http\Request::HEADER_CLIENT_PROTO => 'X_FORWARDED_PROTO',
57+
\Illuminate\Http\Request::HEADER_CLIENT_PORT => 'X_FORWARDED_PORT',
58+
]
59+
];

0 commit comments

Comments
 (0)