From c4444e72e429e85b54bfaea2979b8637b4218c20 Mon Sep 17 00:00:00 2001 From: goemktg Date: Mon, 19 Feb 2024 18:31:04 +0000 Subject: [PATCH 1/2] add TRUSTED_PROXIES env var and sets them when user login/logout --- src/Config/web.config.php | 3 ++- src/Events/Login.php | 4 ++++ src/Events/Logout.php | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Config/web.config.php b/src/Config/web.config.php index 766e6f621..98bb0dbe1 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'), +]; \ No newline at end of file diff --git a/src/Events/Login.php b/src/Events/Login.php index 3db9c8f57..3319264f5 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..6fa345e2e 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'), From 9cc7914347219d7363a9991f685ef44c02d32b11 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Mon, 19 Feb 2024 18:37:07 +0000 Subject: [PATCH 2/2] Apply fixes from StyleCI --- src/Config/web.config.php | 2 +- src/Events/Login.php | 6 +++--- src/Events/Logout.php | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Config/web.config.php b/src/Config/web.config.php index 98bb0dbe1..6df6380e5 100644 --- a/src/Config/web.config.php +++ b/src/Config/web.config.php @@ -23,4 +23,4 @@ return [ 'queue_status_update_time' => 10 * 1000, // milliseconds = seconds x 1,000 'trusted_proxies' => env('TRUSTED_PROXIES'), -]; \ No newline at end of file +]; diff --git a/src/Events/Login.php b/src/Events/Login.php index 3319264f5..e0a43c3f7 100644 --- a/src/Events/Login.php +++ b/src/Events/Login.php @@ -45,9 +45,9 @@ 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); + // 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(); diff --git a/src/Events/Logout.php b/src/Events/Logout.php index 6fa345e2e..30eb58dbe 100644 --- a/src/Events/Logout.php +++ b/src/Events/Logout.php @@ -45,9 +45,9 @@ 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); + // 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(),