Skip to content

Commit 435982b

Browse files
author
Lionel Laské
committed
Merge branch 'pr/1939' into dev
2 parents 4228d06 + 734f973 commit 435982b

File tree

13 files changed

+51
-0
lines changed

13 files changed

+51
-0
lines changed

js/modules/user.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ define([], function() {
5959
return settings && settings.sharedJournal ? settings.sharedJournal : null;
6060
}
6161

62+
// Validate username - returns true if valid, false if contains HTML characters
63+
let validateName = function(name) {
64+
// Check for HTML special characters that could enable XSS
65+
const htmlChars = /[<>&"']/;
66+
return !htmlChars.test(name);
67+
}
68+
6269
// Check if user exists
6370
user.checkIfExists = function(baseurl, name) {
6471
return new Promise((resolve, reject) => {
@@ -89,6 +96,10 @@ define([], function() {
8996

9097
// Signup user
9198
user.signup = async function(baseurl, name, password, color) {
99+
// Validate username - reject if contains HTML characters
100+
if (!validateName(name)) {
101+
throw new Error("Invalid username: contains forbidden characters");
102+
}
92103
const signupData = {
93104
"name": `${name}`,
94105
"password": `${password}`,
@@ -187,6 +198,11 @@ define([], function() {
187198
// Update user information
188199
user.update = function(data, dataLocal = null) {
189200
return new Promise((resolve, reject) => {
201+
// Validate username if being updated - reject if contains HTML characters
202+
if (data.name && !validateName(data.name)) {
203+
reject(new Error("Invalid username: contains forbidden characters"));
204+
return;
205+
}
190206
// update the user locally
191207
sugarizer.modules.settings.setUser(dataLocal ? dataLocal : data);
192208

js/screens/loginscreen.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,14 @@ const LoginScreen = {
266266
}
267267

268268
else if (this.index.currentIndex === 1 && this.details.name.length > 0) { // name
269+
// Validate username - check for HTML characters
270+
const htmlChars = /[<>&"']/;
271+
if (htmlChars.test(this.details.name)) {
272+
this.warning.show = true;
273+
this.warning.text = this.$t("InvalidName");
274+
this.isLoading = false;
275+
return;
276+
}
269277
if (sugarizer.getClientType() === sugarizer.constant.webAppType || this.details.serverAddress.length > 0) {
270278
const info = await sugarizer.modules.server.getServerInformation(this.details.serverAddress);
271279
this.consentNeed = info.options['consent-need'];
@@ -371,6 +379,11 @@ const LoginScreen = {
371379
this.login(this.details.serverAddress, this.details.name, this.details.password);
372380
}, (error) => {
373381
console.log(error);
382+
if (error.message && error.message.includes("Invalid username")) {
383+
this.warning.show = true;
384+
this.warning.text = this.$t("InvalidName");
385+
this.isLoading = false;
386+
}
374387
});
375388
}
376389

js/screens/settings-aboutme.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,11 @@ const AboutMe = {
186186
)
187187
.then(() => {
188188
sugarizer.reload();
189+
}, (error) => {
190+
if (error.message && error.message.includes("Invalid username")) {
191+
this.warning.show = true;
192+
this.warning.text = this.$t("InvalidName");
193+
}
189194
});
190195
},
191196

@@ -196,6 +201,13 @@ const AboutMe = {
196201
this.close('about_me');
197202
return;
198203
}
204+
// Validate username - check for HTML characters
205+
const htmlChars = /[<>&"']/;
206+
if (htmlChars.test(this.name)) {
207+
this.warning.show = true;
208+
this.warning.text = this.$t('InvalidName');
209+
return;
210+
}
199211
if (nameChanged && await sugarizer.modules.user.checkIfExists(null, this.name)) {
200212
this.warning.show = true;
201213
this.warning.text = this.$t('UserAlreadyExist');

locales/ar.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
"ChoosePassword": "Choose at least {{min}} images:",
137137
"UserLoginInvalid": "Invalid user name or images",
138138
"UserAlreadyExist": "User already exist",
139+
"InvalidName": "Invalid user name",
139140
"ServerError": "Server error code {{code}}",
140141
"ServerNotSet": "مُهيّء مزودك غير",
141142
"AndroidSettings": "إعدادات الروبوت",

locales/de.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@
135135
"ChoosePassword": "Wähle zumindest {{min}} Bilder:",
136136
"UserLoginInvalid": "Ungültiger Benutzername oder Bilder",
137137
"UserAlreadyExist": "Benutzer existiert bereits",
138+
"InvalidName": "Ungültiger Benutzername",
138139
"ServerError": "Server error code {{code}}",
139140
"ClickToColor": "Klicke um die Farbe zu setzen:",
140141
"ServerNotSet": "Dein Server ist noch nicht eingetragen",

locales/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
"ChoosePassword": "Choose at least {{min}} images:",
137137
"UserLoginInvalid": "Invalid user name or images",
138138
"UserAlreadyExist": "User already exist",
139+
"InvalidName": "Invalid name",
139140
"ServerError": "Server error code {{code}}",
140141
"ServerNotSet": "Your server is not set",
141142
"AndroidSettings": "Android Settings",

locales/es.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
"ChoosePassword": "Escoge, al menos, {{min}} imágenes:",
137137
"UserLoginInvalid": "Nombre o imágenes de usuario no válidas",
138138
"UserAlreadyExist": "Ese usuario ya existe",
139+
"InvalidName": "Nombre de usuario no válido",
139140
"ServerError": "Server error code {{code}}",
140141
"ServerNotSet": "No se ha especificado el servidor",
141142
"AndroidSettings": "Configuración de Android",

locales/fr.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
"ChoosePassword": "Choisir au moins {{min}} images:",
137137
"UserLoginInvalid": "Nom d'utilisateur ou images invalides",
138138
"UserAlreadyExist": "Cet utilisateur existe déjà",
139+
"InvalidName": "Nom d'utilisateur invalide",
139140
"ServerError": "Erreur serveur code {{code}}",
140141
"ServerNotSet": "Votre serveur n'est pas configuré",
141142
"AndroidSettings": "Paramètres Android",

locales/ibo.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
"ChoosePassword": "Choose at least {{min}} images:",
137137
"UserLoginInvalid": "Invalid user name or images",
138138
"UserAlreadyExist": "User already exist",
139+
"InvalidName": "Invalid user name",
139140
"ServerError": "Server error code {{code}}",
140141
"ServerNotSet": "Gị na ihe nkesa na-adịghị ka",
141142
"AndroidSettings": "android ntọala",

locales/ja.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
"ChoosePassword": "Choose at least {{min}} images:",
137137
"UserLoginInvalid": "Invalid user name or images",
138138
"UserAlreadyExist": "User already exist",
139+
"InvalidName": "Invalid user name",
139140
"ServerError": "Server error code {{code}}",
140141
"ServerNotSet": "サーバーがセットされていません",
141142
"AndroidSettings": "Android の設定",

0 commit comments

Comments
 (0)