From 8b1e2188625e6550795d42714cdf00da18bdc5ea Mon Sep 17 00:00:00 2001 From: Dmitriy Simushev Date: Thu, 9 Mar 2017 13:34:57 +0000 Subject: [PATCH] Add "trusted_proxy" option Fixes #188 --- src/mibew/configs/default_config.yml | 9 +++++++++ src/mibew/libs/init.php | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/src/mibew/configs/default_config.yml b/src/mibew/configs/default_config.yml index 086589e2..76509e12 100644 --- a/src/mibew/configs/default_config.yml +++ b/src/mibew/configs/default_config.yml @@ -77,6 +77,15 @@ default_locale: en # http://php.net/manual/en/timezones.php timezone: "" +# List of proxy's IP Mibew should trust. You should set this option if you use +# Mibew with a load balancer or behind a proxy. +trusted_proxies: [] +# Here is an example of what values this option can take: +# trusted_proxies: +# - 127.0.0.1 +# - ::1 +# - 10.0.0.0/8 + # Plugins plugins: [] diff --git a/src/mibew/libs/init.php b/src/mibew/libs/init.php index 1875beb4..53524fea 100644 --- a/src/mibew/libs/init.php +++ b/src/mibew/libs/init.php @@ -44,6 +44,10 @@ require_once(MIBEW_FS_ROOT . '/libs/common/request.php'); require_once(MIBEW_FS_ROOT . '/libs/common/response.php'); require_once(MIBEW_FS_ROOT . '/libs/common/string.php'); +if (count($configs['trusted_proxies']) > 0) { + \Symfony\Component\HttpFoundation\Request::setTrustedProxies($configs['trusted_proxies']); +} + // We need to get some info from the request. Use symfony wrapper because it's // the simplest way. $tmp_request = \Symfony\Component\HttpFoundation\Request::createFromGlobals();