From 50f87567213e5c272daf583bcc9f34e002753a15 Mon Sep 17 00:00:00 2001 From: Charles Zhao Date: Tue, 30 Jan 2024 12:33:08 +0800 Subject: [PATCH] fix(phrases,shared): only allow lowercase letters, numbers and hyphens in subdomains (#5332) --- .../src/locales/de/translation/admin-console/protected-app.ts | 2 +- .../src/locales/en/translation/admin-console/protected-app.ts | 2 +- .../src/locales/es/translation/admin-console/protected-app.ts | 2 +- .../src/locales/fr/translation/admin-console/protected-app.ts | 2 +- .../src/locales/it/translation/admin-console/protected-app.ts | 2 +- .../src/locales/ja/translation/admin-console/protected-app.ts | 2 +- .../src/locales/ko/translation/admin-console/protected-app.ts | 2 +- .../locales/pl-pl/translation/admin-console/protected-app.ts | 2 +- .../locales/pt-br/translation/admin-console/protected-app.ts | 2 +- .../locales/pt-pt/translation/admin-console/protected-app.ts | 2 +- .../src/locales/ru/translation/admin-console/protected-app.ts | 2 +- .../locales/tr-tr/translation/admin-console/protected-app.ts | 2 +- .../locales/zh-cn/translation/admin-console/protected-app.ts | 2 +- .../locales/zh-hk/translation/admin-console/protected-app.ts | 2 +- .../locales/zh-tw/translation/admin-console/protected-app.ts | 2 +- packages/shared/src/utils/sub-domain.test.ts | 2 ++ packages/shared/src/utils/sub-domain.ts | 2 +- 17 files changed, 18 insertions(+), 16 deletions(-) diff --git a/packages/phrases/src/locales/de/translation/admin-console/protected-app.ts b/packages/phrases/src/locales/de/translation/admin-console/protected-app.ts index 13f8bcbcb..d007c46da 100644 --- a/packages/phrases/src/locales/de/translation/admin-console/protected-app.ts +++ b/packages/phrases/src/locales/de/translation/admin-console/protected-app.ts @@ -46,7 +46,7 @@ const protected_app = { domain_in_use: 'This subdomain name is already in use.', /** UNTRANSLATED */ invalid_domain_format: - "Invalid subdomain format: use only lowercase letters, hyphens '-', and underscores '_'.", + "Invalid subdomain format: use only lowercase letters, numbers, and hyphens '-'.", /** UNTRANSLATED */ url_required: 'Origin URL is required.', /** UNTRANSLATED */ diff --git a/packages/phrases/src/locales/en/translation/admin-console/protected-app.ts b/packages/phrases/src/locales/en/translation/admin-console/protected-app.ts index 95136ef11..133d2a438 100644 --- a/packages/phrases/src/locales/en/translation/admin-console/protected-app.ts +++ b/packages/phrases/src/locales/en/translation/admin-console/protected-app.ts @@ -26,7 +26,7 @@ const protected_app = { domain_required: 'Subdomain is required', domain_in_use: 'This subdomain name is already in use.', invalid_domain_format: - "Invalid subdomain format: use only lowercase letters, hyphens '-', and underscores '_'.", + "Invalid subdomain format: use only lowercase letters, numbers, and hyphens '-'.", url_required: 'Origin URL is required.', invalid_url: "Invalid Origin URL format: Use http:// or https://. Note: '/routes' is not currently supported.", diff --git a/packages/phrases/src/locales/es/translation/admin-console/protected-app.ts b/packages/phrases/src/locales/es/translation/admin-console/protected-app.ts index 13f8bcbcb..d007c46da 100644 --- a/packages/phrases/src/locales/es/translation/admin-console/protected-app.ts +++ b/packages/phrases/src/locales/es/translation/admin-console/protected-app.ts @@ -46,7 +46,7 @@ const protected_app = { domain_in_use: 'This subdomain name is already in use.', /** UNTRANSLATED */ invalid_domain_format: - "Invalid subdomain format: use only lowercase letters, hyphens '-', and underscores '_'.", + "Invalid subdomain format: use only lowercase letters, numbers, and hyphens '-'.", /** UNTRANSLATED */ url_required: 'Origin URL is required.', /** UNTRANSLATED */ diff --git a/packages/phrases/src/locales/fr/translation/admin-console/protected-app.ts b/packages/phrases/src/locales/fr/translation/admin-console/protected-app.ts index 13f8bcbcb..d007c46da 100644 --- a/packages/phrases/src/locales/fr/translation/admin-console/protected-app.ts +++ b/packages/phrases/src/locales/fr/translation/admin-console/protected-app.ts @@ -46,7 +46,7 @@ const protected_app = { domain_in_use: 'This subdomain name is already in use.', /** UNTRANSLATED */ invalid_domain_format: - "Invalid subdomain format: use only lowercase letters, hyphens '-', and underscores '_'.", + "Invalid subdomain format: use only lowercase letters, numbers, and hyphens '-'.", /** UNTRANSLATED */ url_required: 'Origin URL is required.', /** UNTRANSLATED */ diff --git a/packages/phrases/src/locales/it/translation/admin-console/protected-app.ts b/packages/phrases/src/locales/it/translation/admin-console/protected-app.ts index 13f8bcbcb..d007c46da 100644 --- a/packages/phrases/src/locales/it/translation/admin-console/protected-app.ts +++ b/packages/phrases/src/locales/it/translation/admin-console/protected-app.ts @@ -46,7 +46,7 @@ const protected_app = { domain_in_use: 'This subdomain name is already in use.', /** UNTRANSLATED */ invalid_domain_format: - "Invalid subdomain format: use only lowercase letters, hyphens '-', and underscores '_'.", + "Invalid subdomain format: use only lowercase letters, numbers, and hyphens '-'.", /** UNTRANSLATED */ url_required: 'Origin URL is required.', /** UNTRANSLATED */ diff --git a/packages/phrases/src/locales/ja/translation/admin-console/protected-app.ts b/packages/phrases/src/locales/ja/translation/admin-console/protected-app.ts index 13f8bcbcb..d007c46da 100644 --- a/packages/phrases/src/locales/ja/translation/admin-console/protected-app.ts +++ b/packages/phrases/src/locales/ja/translation/admin-console/protected-app.ts @@ -46,7 +46,7 @@ const protected_app = { domain_in_use: 'This subdomain name is already in use.', /** UNTRANSLATED */ invalid_domain_format: - "Invalid subdomain format: use only lowercase letters, hyphens '-', and underscores '_'.", + "Invalid subdomain format: use only lowercase letters, numbers, and hyphens '-'.", /** UNTRANSLATED */ url_required: 'Origin URL is required.', /** UNTRANSLATED */ diff --git a/packages/phrases/src/locales/ko/translation/admin-console/protected-app.ts b/packages/phrases/src/locales/ko/translation/admin-console/protected-app.ts index 13f8bcbcb..d007c46da 100644 --- a/packages/phrases/src/locales/ko/translation/admin-console/protected-app.ts +++ b/packages/phrases/src/locales/ko/translation/admin-console/protected-app.ts @@ -46,7 +46,7 @@ const protected_app = { domain_in_use: 'This subdomain name is already in use.', /** UNTRANSLATED */ invalid_domain_format: - "Invalid subdomain format: use only lowercase letters, hyphens '-', and underscores '_'.", + "Invalid subdomain format: use only lowercase letters, numbers, and hyphens '-'.", /** UNTRANSLATED */ url_required: 'Origin URL is required.', /** UNTRANSLATED */ diff --git a/packages/phrases/src/locales/pl-pl/translation/admin-console/protected-app.ts b/packages/phrases/src/locales/pl-pl/translation/admin-console/protected-app.ts index 13f8bcbcb..d007c46da 100644 --- a/packages/phrases/src/locales/pl-pl/translation/admin-console/protected-app.ts +++ b/packages/phrases/src/locales/pl-pl/translation/admin-console/protected-app.ts @@ -46,7 +46,7 @@ const protected_app = { domain_in_use: 'This subdomain name is already in use.', /** UNTRANSLATED */ invalid_domain_format: - "Invalid subdomain format: use only lowercase letters, hyphens '-', and underscores '_'.", + "Invalid subdomain format: use only lowercase letters, numbers, and hyphens '-'.", /** UNTRANSLATED */ url_required: 'Origin URL is required.', /** UNTRANSLATED */ diff --git a/packages/phrases/src/locales/pt-br/translation/admin-console/protected-app.ts b/packages/phrases/src/locales/pt-br/translation/admin-console/protected-app.ts index 13f8bcbcb..d007c46da 100644 --- a/packages/phrases/src/locales/pt-br/translation/admin-console/protected-app.ts +++ b/packages/phrases/src/locales/pt-br/translation/admin-console/protected-app.ts @@ -46,7 +46,7 @@ const protected_app = { domain_in_use: 'This subdomain name is already in use.', /** UNTRANSLATED */ invalid_domain_format: - "Invalid subdomain format: use only lowercase letters, hyphens '-', and underscores '_'.", + "Invalid subdomain format: use only lowercase letters, numbers, and hyphens '-'.", /** UNTRANSLATED */ url_required: 'Origin URL is required.', /** UNTRANSLATED */ diff --git a/packages/phrases/src/locales/pt-pt/translation/admin-console/protected-app.ts b/packages/phrases/src/locales/pt-pt/translation/admin-console/protected-app.ts index 13f8bcbcb..d007c46da 100644 --- a/packages/phrases/src/locales/pt-pt/translation/admin-console/protected-app.ts +++ b/packages/phrases/src/locales/pt-pt/translation/admin-console/protected-app.ts @@ -46,7 +46,7 @@ const protected_app = { domain_in_use: 'This subdomain name is already in use.', /** UNTRANSLATED */ invalid_domain_format: - "Invalid subdomain format: use only lowercase letters, hyphens '-', and underscores '_'.", + "Invalid subdomain format: use only lowercase letters, numbers, and hyphens '-'.", /** UNTRANSLATED */ url_required: 'Origin URL is required.', /** UNTRANSLATED */ diff --git a/packages/phrases/src/locales/ru/translation/admin-console/protected-app.ts b/packages/phrases/src/locales/ru/translation/admin-console/protected-app.ts index 13f8bcbcb..d007c46da 100644 --- a/packages/phrases/src/locales/ru/translation/admin-console/protected-app.ts +++ b/packages/phrases/src/locales/ru/translation/admin-console/protected-app.ts @@ -46,7 +46,7 @@ const protected_app = { domain_in_use: 'This subdomain name is already in use.', /** UNTRANSLATED */ invalid_domain_format: - "Invalid subdomain format: use only lowercase letters, hyphens '-', and underscores '_'.", + "Invalid subdomain format: use only lowercase letters, numbers, and hyphens '-'.", /** UNTRANSLATED */ url_required: 'Origin URL is required.', /** UNTRANSLATED */ diff --git a/packages/phrases/src/locales/tr-tr/translation/admin-console/protected-app.ts b/packages/phrases/src/locales/tr-tr/translation/admin-console/protected-app.ts index 13f8bcbcb..d007c46da 100644 --- a/packages/phrases/src/locales/tr-tr/translation/admin-console/protected-app.ts +++ b/packages/phrases/src/locales/tr-tr/translation/admin-console/protected-app.ts @@ -46,7 +46,7 @@ const protected_app = { domain_in_use: 'This subdomain name is already in use.', /** UNTRANSLATED */ invalid_domain_format: - "Invalid subdomain format: use only lowercase letters, hyphens '-', and underscores '_'.", + "Invalid subdomain format: use only lowercase letters, numbers, and hyphens '-'.", /** UNTRANSLATED */ url_required: 'Origin URL is required.', /** UNTRANSLATED */ diff --git a/packages/phrases/src/locales/zh-cn/translation/admin-console/protected-app.ts b/packages/phrases/src/locales/zh-cn/translation/admin-console/protected-app.ts index 13f8bcbcb..d007c46da 100644 --- a/packages/phrases/src/locales/zh-cn/translation/admin-console/protected-app.ts +++ b/packages/phrases/src/locales/zh-cn/translation/admin-console/protected-app.ts @@ -46,7 +46,7 @@ const protected_app = { domain_in_use: 'This subdomain name is already in use.', /** UNTRANSLATED */ invalid_domain_format: - "Invalid subdomain format: use only lowercase letters, hyphens '-', and underscores '_'.", + "Invalid subdomain format: use only lowercase letters, numbers, and hyphens '-'.", /** UNTRANSLATED */ url_required: 'Origin URL is required.', /** UNTRANSLATED */ diff --git a/packages/phrases/src/locales/zh-hk/translation/admin-console/protected-app.ts b/packages/phrases/src/locales/zh-hk/translation/admin-console/protected-app.ts index 13f8bcbcb..d007c46da 100644 --- a/packages/phrases/src/locales/zh-hk/translation/admin-console/protected-app.ts +++ b/packages/phrases/src/locales/zh-hk/translation/admin-console/protected-app.ts @@ -46,7 +46,7 @@ const protected_app = { domain_in_use: 'This subdomain name is already in use.', /** UNTRANSLATED */ invalid_domain_format: - "Invalid subdomain format: use only lowercase letters, hyphens '-', and underscores '_'.", + "Invalid subdomain format: use only lowercase letters, numbers, and hyphens '-'.", /** UNTRANSLATED */ url_required: 'Origin URL is required.', /** UNTRANSLATED */ diff --git a/packages/phrases/src/locales/zh-tw/translation/admin-console/protected-app.ts b/packages/phrases/src/locales/zh-tw/translation/admin-console/protected-app.ts index 13f8bcbcb..d007c46da 100644 --- a/packages/phrases/src/locales/zh-tw/translation/admin-console/protected-app.ts +++ b/packages/phrases/src/locales/zh-tw/translation/admin-console/protected-app.ts @@ -46,7 +46,7 @@ const protected_app = { domain_in_use: 'This subdomain name is already in use.', /** UNTRANSLATED */ invalid_domain_format: - "Invalid subdomain format: use only lowercase letters, hyphens '-', and underscores '_'.", + "Invalid subdomain format: use only lowercase letters, numbers, and hyphens '-'.", /** UNTRANSLATED */ url_required: 'Origin URL is required.', /** UNTRANSLATED */ diff --git a/packages/shared/src/utils/sub-domain.test.ts b/packages/shared/src/utils/sub-domain.test.ts index e89a797f6..0515a92ce 100644 --- a/packages/shared/src/utils/sub-domain.test.ts +++ b/packages/shared/src/utils/sub-domain.test.ts @@ -14,5 +14,7 @@ describe('isValidSubdomain()', () => { expect(isValidSubdomain('-a1')).toBe(false); expect(isValidSubdomain('a1-')).toBe(false); expect(isValidSubdomain('a1.b')).toBe(false); + expect(isValidSubdomain('a_b')).toBe(false); + expect(isValidSubdomain('aBc')).toBe(false); }); }); diff --git a/packages/shared/src/utils/sub-domain.ts b/packages/shared/src/utils/sub-domain.ts index 31dd700d0..7508ccb79 100644 --- a/packages/shared/src/utils/sub-domain.ts +++ b/packages/shared/src/utils/sub-domain.ts @@ -4,4 +4,4 @@ * @returns boolean indicating whether the subdomain is valid */ export const isValidSubdomain = (subdomain: string): boolean => - /^([\da-z]([\da-z-]{0,61}[\da-z])?)$/i.test(subdomain); + /^([\da-z]([\da-z-]{0,61}[\da-z])?)$/.test(subdomain);