@@ -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
0 commit comments