From 3fa38fb4203986b20a5b4f8d33e3fdc7857c1ca6 Mon Sep 17 00:00:00 2001 From: Ildar Kamalov Date: Fri, 15 Oct 2021 15:01:50 +0300 Subject: [PATCH] Pull request: 3684 validate client id in the mobileconfig form Closes #3684 Squashed commit of the following: commit 78e9862f7a06262f91c28d6ddcc10512560eedae Author: Ildar Kamalov Date: Fri Oct 15 14:39:36 2021 +0300 fix build commit 3ed4ee69590f238396dd3aab2b62f110baa6d681 Author: Ildar Kamalov Date: Fri Oct 15 13:39:12 2021 +0300 client: validate client id in the mobileconfig form --- .../src/components/ui/Guide/MobileConfigForm.js | 4 ++-- client/src/helpers/constants.js | 2 +- client/src/helpers/validators.js | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/client/src/components/ui/Guide/MobileConfigForm.js b/client/src/components/ui/Guide/MobileConfigForm.js index ce9a6942..f726b40c 100644 --- a/client/src/components/ui/Guide/MobileConfigForm.js +++ b/client/src/components/ui/Guide/MobileConfigForm.js @@ -14,7 +14,7 @@ import { toNumber, } from '../../../helpers/form'; import { - validateClientId, + validateConfigClientId, validateServerName, validatePort, validateIsSafePort, @@ -132,7 +132,7 @@ const MobileConfigForm = ({ invalid }) => { component={renderInputField} className="form-control" placeholder={i18next.t('client_id_placeholder')} - validate={validateClientId} + validate={validateConfigClientId} />
diff --git a/client/src/helpers/constants.js b/client/src/helpers/constants.js index f9431cf6..195efdb3 100644 --- a/client/src/helpers/constants.js +++ b/client/src/helpers/constants.js @@ -24,7 +24,7 @@ export const R_UNIX_ABSOLUTE_PATH = /^(\/[^/\x00]+)+$/; // eslint-disable-next-line no-control-regex export const R_WIN_ABSOLUTE_PATH = /^([a-zA-Z]:)?(\\|\/)(?:[^\\/:*?"<>|\x00]+\\)*[^\\/:*?"<>|\x00]*$/; -export const R_CLIENT_ID = /^[a-z0-9-]{1,64}$/; +export const R_CLIENT_ID = /^[a-z0-9-]{1,63}$/; export const HTML_PAGES = { INSTALL: '/install.html', diff --git a/client/src/helpers/validators.js b/client/src/helpers/validators.js index 25a7168d..7075ca47 100644 --- a/client/src/helpers/validators.js +++ b/client/src/helpers/validators.js @@ -83,6 +83,21 @@ export const validateClientId = (value) => { return undefined; }; +/** + * @param value {string} + * @returns {undefined|string} + */ +export const validateConfigClientId = (value) => { + if (!value) { + return undefined; + } + const formattedValue = value.trim(); + if (formattedValue && !R_CLIENT_ID.test(formattedValue)) { + return 'form_error_client_id_format'; + } + return undefined; +}; + /** * @param value {string} * @returns {undefined|string}