Skip to content

Commit 3155ff7

Browse files
author
Lionel Laské
committed
Merge branch 'fix/chat-xss-vulnerability' of https://github.com/Alok-2005/sugarizer into pr/1939
2 parents aad3d62 + e1b2df1 commit 3155ff7

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,11 @@ const LoginScreen = {
371371
this.login(this.details.serverAddress, this.details.name, this.details.password);
372372
}, (error) => {
373373
console.log(error);
374+
if (error.message && error.message.includes("Invalid username")) {
375+
this.warning.show = true;
376+
this.warning.text = this.$t("InvalidName");
377+
this.isLoading = false;
378+
}
374379
});
375380
}
376381

js/screens/settings-aboutme.js

Lines changed: 5 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

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",

0 commit comments

Comments
 (0)