Skip to content

Commit 977b6ca

Browse files
committed
Internal: Add support for reverse proxies by taking the TRUSTED_PROXIES settings from .env into account
1 parent 68813ee commit 977b6ca

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

.env.dist

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ DATABASE_PASSWORD='{{DATABASE_PASSWORD}}'
1919
APP_ENV='dev'
2020
APP_SECRET='{{APP_SECRET}}'
2121
APP_DEBUG='1'
22-
#TRUSTED_PROXIES=127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16
22+
TRUSTED_PROXIES=127.0.0.1
2323
#TRUSTED_HOSTS='^(localhost|example\.com)$'
2424
###< symfony/framework-bundle ###
2525

config/packages/framework.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ framework:
1818
php_errors:
1919
log: true
2020
serializer: {enable_annotations: true}
21+
trusted_proxies: '%env(TRUSTED_PROXIES)%'
22+
trusted_headers: ['x-forwarded-for', 'x-forwarded-host', 'x-forwarded-proto', 'x-forwarded-port']
23+
# For legacy code (ending in ".php"), also edit public/main/inc/global.inc.php according to the changes you make here
2124

2225
when@test:
2326
framework:

public/main/inc/global.inc.php

+7
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@
6868
$kernel = new Chamilo\Kernel($env, $debug);
6969
// Loading Request from Sonata. In order to use Sonata Pages Bundle.
7070
$request = Request::createFromGlobals();
71+
if (!empty($_SERVER['TRUSTED_PROXIES'])) {
72+
$request->setTrustedProxies(
73+
preg_split('#,#', $_SERVER['TRUSTED_PROXIES']),
74+
Request::HEADER_X_FORWARDED_FOR | Request::HEADER_X_FORWARDED_PROTO | Request::HEADER_X_FORWARDED_HOST | Request::HEADER_X_FORWARDED_PORT
75+
);
76+
// TRUSTED_PROXIES must be defined in .env. For non-legacy code, check config/packages/framework.yaml
77+
}
7178
// This 'load_legacy' variable is needed to know that symfony is loaded using old style legacy mode,
7279
// and not called from a symfony controller from public/
7380
$request->request->set('load_legacy', true);

0 commit comments

Comments
 (0)