[FrameworkBundle] Add a env vars to configure trusted proxies and hosts

This commit is contained in:
Kévin Dunglas
2017-11-30 18:13:11 +01:00
parent a9c8b00077
commit 629e7320c3
3 changed files with 10 additions and 3 deletions
@@ -3,7 +3,6 @@ framework:
#default_locale: en
#csrf_protection: ~
#http_method_override: true
#trusted_hosts: ~
# uncomment this entire section to enable sessions
#session:
+3 -1
View File
@@ -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",
@@ -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();