Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): reject a session name shorter than 3 characters

Yudhi Armyndharisc71375a78e17
diff --git a/dashboard/src/i18n/locales/ar.json b/dashboard/src/i18n/locales/ar.json
index da0d5df08..ec66805d3 100644
--- a/dashboard/src/i18n/locales/ar.json
+++ b/dashboard/src/i18n/locales/ar.json
@@ -307,7 +307,8 @@
"successTitle": "تم إنشاء الجلسة",
"successDesc": "تم إنشاء الجلسة \"{{name}}\" بنجاح",
"errorTitle": "فشل الإنشاء",
- "errorDefault": "فشل إنشاء الجلسة"
+ "errorDefault": "فشل إنشاء الجلسة",
+ "tooShort": "يجب أن يتكون الاسم من 3 أحرف على الأقل."
},
"delete": {
"title": "تأكيد الحذف",
diff --git a/dashboard/src/i18n/locales/de.json b/dashboard/src/i18n/locales/de.json
index 466b09f97..6f1dac381 100644
--- a/dashboard/src/i18n/locales/de.json
+++ b/dashboard/src/i18n/locales/de.json
@@ -294,7 +294,8 @@
"successTitle": "Sitzung erstellt",
"successDesc": "Sitzung „{{name}}“ wurde erfolgreich erstellt",
"errorTitle": "Erstellung fehlgeschlagen",
- "errorDefault": "Sitzung konnte nicht erstellt werden"
+ "errorDefault": "Sitzung konnte nicht erstellt werden",
+ "tooShort": "Der Name muss mindestens 3 Zeichen lang sein."
},
"delete": {
"title": "Löschen bestätigen",
diff --git a/dashboard/src/i18n/locales/en.json b/dashboard/src/i18n/locales/en.json
index 12ae54194..12f822ace 100644
--- a/dashboard/src/i18n/locales/en.json
+++ b/dashboard/src/i18n/locales/en.json
@@ -294,7 +294,8 @@
"successTitle": "Session Created",
"successDesc": "Session \"{{name}}\" created successfully",
"errorTitle": "Create Failed",
- "errorDefault": "Failed to create session"
+ "errorDefault": "Failed to create session",
+ "tooShort": "Name must be at least 3 characters."
},
"delete": {
"title": "Confirm Delete",
diff --git a/dashboard/src/i18n/locales/es.json b/dashboard/src/i18n/locales/es.json
index ba09f4e03..0cf682864 100644
--- a/dashboard/src/i18n/locales/es.json
+++ b/dashboard/src/i18n/locales/es.json
@@ -297,7 +297,8 @@
"successTitle": "Sesión creada",
"successDesc": "Sesión \"{{name}}\" creada correctamente",
"errorTitle": "Error al crear",
- "errorDefault": "No se pudo crear la sesión"
+ "errorDefault": "No se pudo crear la sesión",
+ "tooShort": "El nombre debe tener al menos 3 caracteres."
},
"delete": {
"title": "Confirmar eliminación",
diff --git a/dashboard/src/i18n/locales/fr.json b/dashboard/src/i18n/locales/fr.json
index 55274030c..fc078602e 100644
--- a/dashboard/src/i18n/locales/fr.json
+++ b/dashboard/src/i18n/locales/fr.json
@@ -297,7 +297,8 @@
"successTitle": "Session créée",
"successDesc": "La session \"{{name}}\" a été créée avec succès",
"errorTitle": "Échec de la création",
- "errorDefault": "Impossible de créer la session"
+ "errorDefault": "Impossible de créer la session",
+ "tooShort": "Le nom doit contenir au moins 3 caractères."
},
"delete": {
"title": "Confirmer la suppression",
diff --git a/dashboard/src/i18n/locales/he.json b/dashboard/src/i18n/locales/he.json
index 67bba3a09..67b46344b 100644
--- a/dashboard/src/i18n/locales/he.json
+++ b/dashboard/src/i18n/locales/he.json
@@ -301,7 +301,8 @@
"successTitle": "ה-Session נוצר",
"successDesc": "Session \"{{name}}\" נוצר בהצלחה",
"errorTitle": "היצירה נכשלה",
- "errorDefault": "יצירת ה-Session נכשלה"
+ "errorDefault": "יצירת ה-Session נכשלה",
+ "tooShort": "השם חייב להכיל לפחות 3 תווים."
},
"delete": {
"title": "אישור מחיקה",
diff --git a/dashboard/src/i18n/locales/hi.json b/dashboard/src/i18n/locales/hi.json
index 44f05ef0b..2ffd12dab 100644
--- a/dashboard/src/i18n/locales/hi.json
+++ b/dashboard/src/i18n/locales/hi.json
@@ -294,7 +294,8 @@
"successTitle": "सत्र बनाया गया",
"successDesc": "सत्र \"{{name}}\" सफलतापूर्वक बनाया गया",
"errorTitle": "बनाना विफल",
- "errorDefault": "सत्र बनाने में विफल"
+ "errorDefault": "सत्र बनाने में विफल",
+ "tooShort": "नाम कम से कम 3 वर्णों का होना चाहिए।"
},
"delete": {
"title": "हटाने की पुष्टि करें",
diff --git a/dashboard/src/i18n/locales/it.json b/dashboard/src/i18n/locales/it.json
index 4e8711653..57fccd624 100644
--- a/dashboard/src/i18n/locales/it.json
+++ b/dashboard/src/i18n/locales/it.json
@@ -297,7 +297,8 @@
"successTitle": "Sessione Creata",
"successDesc": "Sessione \"{{name}}\" creata con successo",
"errorTitle": "Creazione Fallita",
- "errorDefault": "Impossibile creare la sessione"
+ "errorDefault": "Impossibile creare la sessione",
+ "tooShort": "Il nome deve contenere almeno 3 caratteri."
},
"delete": {
"title": "Conferma Eliminazione",
diff --git a/dashboard/src/i18n/locales/ko.json b/dashboard/src/i18n/locales/ko.json
index 5751e6b25..363596020 100644
--- a/dashboard/src/i18n/locales/ko.json
+++ b/dashboard/src/i18n/locales/ko.json
@@ -294,7 +294,8 @@
"successTitle": "세션 생성 완료",
"successDesc": "\"{{name}}\" 세션이 생성되었습니다",
"errorTitle": "생성 실패",
- "errorDefault": "세션을 생성하지 못했습니다"
+ "errorDefault": "세션을 생성하지 못했습니다",
+ "tooShort": "이름은 3자 이상이어야 합니다."
},
"delete": {
"title": "삭제 확인",
diff --git a/dashboard/src/i18n/locales/pt-BR.json b/dashboard/src/i18n/locales/pt-BR.json
index 7bf9a8fca..e68e90257 100644
--- a/dashboard/src/i18n/locales/pt-BR.json
+++ b/dashboard/src/i18n/locales/pt-BR.json
@@ -297,7 +297,8 @@
"successTitle": "Sessão criada",
"successDesc": "Sessão \"{{name}}\" criada com sucesso",
"errorTitle": "Erro ao criar",
- "errorDefault": "Não foi possível criar a sessão"
+ "errorDefault": "Não foi possível criar a sessão",
+ "tooShort": "O nome deve ter pelo menos 3 caracteres."
},
"delete": {
"title": "Confirmar exclusão",
diff --git a/dashboard/src/i18n/locales/te.json b/dashboard/src/i18n/locales/te.json
index 6cb27c0f5..fa8b723b6 100644
--- a/dashboard/src/i18n/locales/te.json
+++ b/dashboard/src/i18n/locales/te.json
@@ -294,7 +294,8 @@
"successTitle": "సెషన్ సృష్టించబడింది",
"successDesc": "సెషన్ \"{{name}}\" విజయవంతంగా సృష్టించబడింది",
"errorTitle": "సృష్టి విఫలమైంది",
- "errorDefault": "సెషన్‌ను సృష్టించడం విఫలమైంది"
+ "errorDefault": "సెషన్‌ను సృష్టించడం విఫలమైంది",
+ "tooShort": "పేరు కనీసం 3 అక్షరాలు ఉండాలి."
},
"delete": {
"title": "తొలగింపును ధృవీకరించండి",
diff --git a/dashboard/src/i18n/locales/tr.json b/dashboard/src/i18n/locales/tr.json
index 95d6e09f7..19c37689a 100644
--- a/dashboard/src/i18n/locales/tr.json
+++ b/dashboard/src/i18n/locales/tr.json
@@ -294,7 +294,8 @@
"successTitle": "Oturum Oluşturuldu",
"successDesc": "\"{{name}}\" oturumu başarıyla oluşturuldu",
"errorTitle": "Oluşturma Başarısız",
- "errorDefault": "Oturum oluşturulamadı"
+ "errorDefault": "Oturum oluşturulamadı",
+ "tooShort": "Ad en az 3 karakter olmalıdır."
},
"delete": {
"title": "Silmeyi Onayla",
diff --git a/dashboard/src/i18n/locales/zh-CN.json b/dashboard/src/i18n/locales/zh-CN.json
index a76d96295..ff0a77314 100644
--- a/dashboard/src/i18n/locales/zh-CN.json
+++ b/dashboard/src/i18n/locales/zh-CN.json
@@ -294,7 +294,8 @@
"successTitle": "会话已创建",
"successDesc": "会话 \"{{name}}\" 已成功创建",
"errorTitle": "创建失败",
- "errorDefault": "创建会话失败"
+ "errorDefault": "创建会话失败",
+ "tooShort": "名称至少需要 3 个字符。"
},
"delete": {
"title": "确认删除",
diff --git a/dashboard/src/i18n/locales/zh-HK.json b/dashboard/src/i18n/locales/zh-HK.json
index 3f3fdaebf..86516db2c 100644
--- a/dashboard/src/i18n/locales/zh-HK.json
+++ b/dashboard/src/i18n/locales/zh-HK.json
@@ -294,7 +294,8 @@
"successTitle": "工作階段已建立",
"successDesc": "工作階段 \"{{name}}\" 已成功建立",
"errorTitle": "建立失敗",
- "errorDefault": "建立工作階段失敗"
+ "errorDefault": "建立工作階段失敗",
+ "tooShort": "名稱至少需要 3 個字元。"
},
"delete": {
"title": "確認刪除",
diff --git a/dashboard/src/pages/Sessions.tsx b/dashboard/src/pages/Sessions.tsx
index b70212053..4918dbe0f 100644
--- a/dashboard/src/pages/Sessions.tsx
+++ b/dashboard/src/pages/Sessions.tsx
@@ -685,6 +685,7 @@ export function Sessions() {
<Trans i18nKey="sessions.create.hint" components={{ code: <code /> }} />
</p>
{nameIssues.includes('format') && <p className="input-error">{t('sessions.create.invalidChars')}</p>}
+ {nameIssues.includes('too-short') && <p className="input-error">{t('sessions.create.tooShort')}</p>}
{nameIssues.includes('too-long') && (
<p className="input-error">{t('sessions.create.tooLong', { length: newSessionName.length })}</p>
)}
diff --git a/dashboard/src/utils/sessionForm.test.ts b/dashboard/src/utils/sessionForm.test.ts
index 7dd8c1245..0ec50ab7f 100644
--- a/dashboard/src/utils/sessionForm.test.ts
+++ b/dashboard/src/utils/sessionForm.test.ts
@@ -44,6 +44,13 @@ test('the length cap is 50', () => {
assert.deepEqual(sessionNameIssues('a'.repeat(51), []), ['too-long']);
});
+test('the gateway rejects a name under 3 characters, so the form does too', () => {
+ assert.deepEqual(sessionNameIssues('ab', []), ['too-short']);
+ assert.deepEqual(sessionNameIssues('a', ['a']), ['too-short'], 'duplicate stays suppressed');
+ assert.deepEqual(sessionNameIssues('abc', []), []);
+ assert.equal(canCreateSession('ab', []), false);
+});
+
test('pairing accepts a bare international number and nothing else', () => {
assert.equal(isValidPairingPhone('628123456789'), true);
assert.equal(isValidPairingPhone(' 628123456789 '), true, 'trimmed');
diff --git a/dashboard/src/utils/sessionForm.ts b/dashboard/src/utils/sessionForm.ts
index 808db3ad1..266fc3f4a 100644
--- a/dashboard/src/utils/sessionForm.ts
+++ b/dashboard/src/utils/sessionForm.ts
@@ -8,10 +8,11 @@
*/
/** Everything wrong with a proposed session name. Empty when it is acceptable. */
-export type SessionNameIssue = 'empty' | 'format' | 'too-long' | 'duplicate';
+export type SessionNameIssue = 'empty' | 'format' | 'too-short' | 'too-long' | 'duplicate';
/** Names become on-disk directory names, so the format is deliberately narrow. */
const NAME_FORMAT = /^[a-z0-9-]+$/;
+const NAME_MIN_LENGTH = 3;
const NAME_MAX_LENGTH = 50;
/**
@@ -25,6 +26,7 @@ export function sessionNameIssues(name: string, existingNames: string[]): Sessio
if (!name.trim()) return ['empty'];
const issues: SessionNameIssue[] = [];
if (!NAME_FORMAT.test(name)) issues.push('format');
+ if (name.length < NAME_MIN_LENGTH) issues.push('too-short');
if (name.length > NAME_MAX_LENGTH) issues.push('too-long');
if (issues.length === 0 && existingNames.includes(name)) issues.push('duplicate');
return issues;