diff --git a/src/Config/web.config.php b/src/Config/web.config.php index 766e6f621..6df6380e5 100644 --- a/src/Config/web.config.php +++ b/src/Config/web.config.php @@ -22,4 +22,5 @@ return [ 'queue_status_update_time' => 10 * 1000, // milliseconds = seconds x 1,000 + 'trusted_proxies' => env('TRUSTED_PROXIES'), ]; diff --git a/src/Events/Login.php b/src/Events/Login.php index 3db9c8f57..e0a43c3f7 100644 --- a/src/Events/Login.php +++ b/src/Events/Login.php @@ -45,6 +45,10 @@ public static function handle(LoginEvent $event) if (session()->has('impersonation_origin')) return; + // Adds trusted proxies if exists. + if (! empty($trusted_proxies = config('web.config.trusted_proxies'))) + Request::setTrustedProxies(explode(',', $trusted_proxies), 0b00010); + // Create a log entry for this login. $event->user->last_login_source = Request::getClientIp(); $event->user->last_login = new DateTime(); diff --git a/src/Events/Logout.php b/src/Events/Logout.php index 708f49aef..30eb58dbe 100644 --- a/src/Events/Logout.php +++ b/src/Events/Logout.php @@ -45,6 +45,10 @@ public static function handle(LogoutEvent $event) if (! $event->user) return; + // Adds trusted proxies if exists. + if (! empty($trusted_proxies = config('web.config.trusted_proxies'))) + Request::setTrustedProxies(explode(',', $trusted_proxies), 0b00010); + $event->user->login_history()->save(new UserLoginHistory([ 'source' => Request::getClientIp(), 'user_agent' => Request::header('User-Agent'),