From 5f0c13b73b83c5412e4dfab3e3df225e8c52b9ef Mon Sep 17 00:00:00 2001 From: Jon Bendtsen Date: Fri, 15 Mar 2024 20:04:03 +0100 Subject: [PATCH 1/4] only if supplied 'account' numbers match will we actually delete, else return 416. Return 401 when not authorized --- htdocs/societe/class/api_thirdparties.class.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/htdocs/societe/class/api_thirdparties.class.php b/htdocs/societe/class/api_thirdparties.class.php index dfd78b08cd6..f4aad4569bf 100644 --- a/htdocs/societe/class/api_thirdparties.class.php +++ b/htdocs/societe/class/api_thirdparties.class.php @@ -1266,18 +1266,20 @@ class Thirdparties extends DolibarrApi public function deleteCompanyBankAccount($id, $bankaccount_id) { if (!DolibarrApiAccess::$user->hasRight('societe', 'creer')) { - throw new RestException(403); + throw new RestException(401); } $account = new CompanyBankAccount($this->db); $account->fetch($bankaccount_id); - if (!$account->socid == $id) { - throw new RestException(403); - } + $socid = (int) $account->socid; - return $account->delete(DolibarrApiAccess::$user); + if ($account->socid == $id) { + return $account->delete(DolibarrApiAccess::$user); + } else { + throw new RestException(416); + } } /** From 434d4d2a0d0caa156e95073049f193761f1a3324 Mon Sep 17 00:00:00 2001 From: Jon Bendtsen Date: Fri, 15 Mar 2024 20:07:56 +0100 Subject: [PATCH 2/4] using the type casted variable in if --- htdocs/societe/class/api_thirdparties.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/societe/class/api_thirdparties.class.php b/htdocs/societe/class/api_thirdparties.class.php index f4aad4569bf..fb67a582612 100644 --- a/htdocs/societe/class/api_thirdparties.class.php +++ b/htdocs/societe/class/api_thirdparties.class.php @@ -1275,7 +1275,7 @@ class Thirdparties extends DolibarrApi $socid = (int) $account->socid; - if ($account->socid == $id) { + if ($socid == $id) { return $account->delete(DolibarrApiAccess::$user); } else { throw new RestException(416); From 081b5a256ffed20f7487e06681f9dae3521a23f8 Mon Sep 17 00:00:00 2001 From: Jon Bendtsen Date: Fri, 15 Mar 2024 21:52:59 +0100 Subject: [PATCH 3/4] 403 when loggin is ok but permission are wrong. --- htdocs/societe/class/api_thirdparties.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/societe/class/api_thirdparties.class.php b/htdocs/societe/class/api_thirdparties.class.php index fb67a582612..ee5403e2d0f 100644 --- a/htdocs/societe/class/api_thirdparties.class.php +++ b/htdocs/societe/class/api_thirdparties.class.php @@ -1266,7 +1266,7 @@ class Thirdparties extends DolibarrApi public function deleteCompanyBankAccount($id, $bankaccount_id) { if (!DolibarrApiAccess::$user->hasRight('societe', 'creer')) { - throw new RestException(401); + throw new RestException(403); } $account = new CompanyBankAccount($this->db); From db18ba99bd4d0528e1c9275f6c54cf3c663e6c3e Mon Sep 17 00:00:00 2001 From: Jon Bendtsen Date: Fri, 15 Mar 2024 22:30:55 +0100 Subject: [PATCH 4/4] writing why it is not allowed --- htdocs/societe/class/api_thirdparties.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/societe/class/api_thirdparties.class.php b/htdocs/societe/class/api_thirdparties.class.php index ee5403e2d0f..f91fb19bf4a 100644 --- a/htdocs/societe/class/api_thirdparties.class.php +++ b/htdocs/societe/class/api_thirdparties.class.php @@ -1278,7 +1278,7 @@ class Thirdparties extends DolibarrApi if ($socid == $id) { return $account->delete(DolibarrApiAccess::$user); } else { - throw new RestException(416); + throw new RestException(403, "Not allowed due to bad consistency of input data"); } }