From c3dafa05c083fd29317528d0ba3b2ebc1af80e50 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 14 Aug 2023 12:25:52 +0200 Subject: [PATCH] Add a better error message on API login if token is not valid. --- htdocs/api/class/api_login.class.php | 3 +++ htdocs/core/lib/functions.lib.php | 2 ++ 2 files changed, 5 insertions(+) diff --git a/htdocs/api/class/api_login.class.php b/htdocs/api/class/api_login.class.php index 64c205ba6d8..e69de5f62fc 100644 --- a/htdocs/api/class/api_login.class.php +++ b/htdocs/api/class/api_login.class.php @@ -167,6 +167,9 @@ class Login } } else { $token = $tmpuser->api_key; + if (!utf8_check($token)) { + throw new RestException(500, 'Error, the API token of this user has a non valid value. Try to update it with a valid value.'); + } } //return token diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 59c4e9aa68b..2e1d6070672 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -8979,6 +8979,7 @@ function dol_sort_array(&$array, $index, $order = 'asc', $natsort = 0, $case_sen * * @param string $str String to check * @return boolean True if string is UTF8 or ISO compatible with UTF8, False if not (ISO with special char or Binary) + * @see utf8_valid() */ function utf8_check($str) { @@ -9016,6 +9017,7 @@ function utf8_check($str) * * @param string $str String to check * @return boolean True if string is valid UTF8 string, false if corrupted + * @see utf8_check() */ function utf8_valid($str) {