fix: phone number parsing exception handling

This commit is contained in:
Chirag Aggarwal 2025-01-20 05:44:19 +00:00
parent 37fc9fdcd3
commit 7315294555

View file

@ -28,6 +28,7 @@ use Appwrite\Utopia\Database\Validator\CustomId;
use Appwrite\Utopia\Database\Validator\Queries\Identities;
use Appwrite\Utopia\Request;
use Appwrite\Utopia\Response;
use libphonenumber\NumberParseException;
use libphonenumber\PhoneNumberUtil;
use MaxMind\Db\Reader;
use Utopia\Abuse\Abuse;
@ -2467,7 +2468,12 @@ App::post('/v1/account/tokens/phone')
$abuse = new Abuse($timelimit);
if ($abuse->check() && System::getEnv('_APP_OPTIONS_ABUSE', 'enabled') === 'enabled') {
$helper = PhoneNumberUtil::getInstance();
$countryCode = $helper->parse($phone)->getCountryCode();
try {
$countryCode = $helper->parse($phone)->getCountryCode();
} catch (NumberParseException $e) {
throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'Invalid phone number');
}
if (!empty($countryCode)) {
$queueForUsage
@ -3587,7 +3593,12 @@ App::post('/v1/account/verification/phone')
$abuse = new Abuse($timelimit);
if ($abuse->check() && System::getEnv('_APP_OPTIONS_ABUSE', 'enabled') === 'enabled') {
$helper = PhoneNumberUtil::getInstance();
$countryCode = $helper->parse($phone)->getCountryCode();
try {
$countryCode = $helper->parse($phone)->getCountryCode();
} catch (NumberParseException $e) {
throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'Invalid phone number');
}
if (!empty($countryCode)) {
$queueForUsage
@ -4148,7 +4159,12 @@ App::post('/v1/account/mfa/challenge')
$abuse = new Abuse($timelimit);
if ($abuse->check() && System::getEnv('_APP_OPTIONS_ABUSE', 'enabled') === 'enabled') {
$helper = PhoneNumberUtil::getInstance();
$countryCode = $helper->parse($phone)->getCountryCode();
try {
$countryCode = $helper->parse($phone)->getCountryCode();
} catch (NumberParseException $e) {
throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'Invalid phone number');
}
if (!empty($countryCode)) {
$queueForUsage