From 5e6c94d30720714c819b506de5a289e7584d8b29 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Mon, 18 Mar 2024 12:41:51 +0000 Subject: [PATCH] chore: update checks --- app/controllers/api/avatars.php | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/app/controllers/api/avatars.php b/app/controllers/api/avatars.php index b9df4b6345..734cfb2dc5 100644 --- a/app/controllers/api/avatars.php +++ b/app/controllers/api/avatars.php @@ -285,10 +285,14 @@ App::get('/v1/avatars/image') } $client = new Client(); - $res = $client + try { + $res = $client ->setAllowRedirects(false) ->fetch($url); - + } catch (\Throwable) { + throw new Exception(Exception::AVATAR_REMOTE_URL_FAILED); + } + if ($res->getStatusCode() !== 200) { throw new Exception(Exception::AVATAR_IMAGE_NOT_FOUND); } @@ -344,7 +348,8 @@ App::get('/v1/avatars/favicon') } $client = new Client(); - $res = $client + try { + $res = $client ->setAllowRedirects(false) ->setUserAgent(\sprintf( APP_USERAGENT, @@ -352,7 +357,10 @@ App::get('/v1/avatars/favicon') App::getEnv('_APP_SYSTEM_SECURITY_EMAIL_ADDRESS', APP_EMAIL_SECURITY) )) ->fetch($url); - + } catch (\Throwable) { + throw new Exception(Exception::AVATAR_REMOTE_URL_FAILED); + } + if ($res->getStatusCode() !== 200) { throw new Exception(Exception::AVATAR_REMOTE_URL_FAILED); } @@ -415,9 +423,13 @@ App::get('/v1/avatars/favicon') } $client = new Client(); - $res = $client - ->setAllowRedirects(false) - ->fetch($outputHref); + try { + $res = $client + ->setAllowRedirects(false) + ->fetch($outputHref); + } catch (\Throwable) { + throw new Exception(Exception::AVATAR_REMOTE_URL_FAILED); + } if ($res->getStatusCode() !== 200) { throw new Exception(Exception::AVATAR_ICON_NOT_FOUND);