From 629e7320c33de81254db5130bdd96bfd0e7d3c30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Wed, 20 Sep 2017 08:54:02 +0200 Subject: [PATCH] [FrameworkBundle] Add a env vars to configure trusted proxies and hosts --- .../framework-bundle/3.3/config/packages/framework.yaml | 1 - symfony/framework-bundle/3.3/manifest.json | 4 +++- symfony/framework-bundle/3.3/public/index.php | 8 +++++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/symfony/framework-bundle/3.3/config/packages/framework.yaml b/symfony/framework-bundle/3.3/config/packages/framework.yaml index bc68ab73..b32f52d9 100644 --- a/symfony/framework-bundle/3.3/config/packages/framework.yaml +++ b/symfony/framework-bundle/3.3/config/packages/framework.yaml @@ -3,7 +3,6 @@ framework: #default_locale: en #csrf_protection: ~ #http_method_override: true - #trusted_hosts: ~ # uncomment this entire section to enable sessions #session: diff --git a/symfony/framework-bundle/3.3/manifest.json b/symfony/framework-bundle/3.3/manifest.json index cada9b41..1f02a829 100644 --- a/symfony/framework-bundle/3.3/manifest.json +++ b/symfony/framework-bundle/3.3/manifest.json @@ -13,7 +13,9 @@ }, "env": { "APP_ENV": "dev", - "APP_SECRET": "%generate(secret)%" + "APP_SECRET": "%generate(secret)%", + "#APP_TRUSTED_PROXIES": "127.0.0.1,127.0.0.2", + "#APP_TRUSTED_HOSTS": "localhost,example.com" }, "gitignore": [ ".env", diff --git a/symfony/framework-bundle/3.3/public/index.php b/symfony/framework-bundle/3.3/public/index.php index 3c7ed08f..ad54fa17 100644 --- a/symfony/framework-bundle/3.3/public/index.php +++ b/symfony/framework-bundle/3.3/public/index.php @@ -21,7 +21,13 @@ if ($_SERVER['APP_DEBUG'] ?? ('prod' !== ($_SERVER['APP_ENV'] ?? 'dev'))) { Debug::enable(); } -// Request::setTrustedProxies(['0.0.0.0/0'], Request::HEADER_FORWARDED); +if ($trustedProxies = $_SERVER['APP_TRUSTED_PROXIES'] ?? false) { + Request::setTrustedProxies(explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST); +} + +if ($trustedHosts = $_SERVER['APP_TRUSTED_HOSTS'] ?? false) { + Request::setTrustedHosts(explode(',', $trustedHosts)); +} $kernel = new Kernel($_SERVER['APP_ENV'] ?? 'dev', $_SERVER['APP_DEBUG'] ?? ('prod' !== ($_SERVER['APP_ENV'] ?? 'dev'))); $request = Request::createFromGlobals();