diff --git a/server/src/service/business/userService.js b/server/src/service/business/userService.js index e69796ec4..612f97a5a 100644 --- a/server/src/service/business/userService.js +++ b/server/src/service/business/userService.js @@ -85,12 +85,18 @@ class UserService { // Check if user exists try { const user = await this.db.userModule.getUserByEmail(email); + + // Add null check before password comparison + if (!user || !user.comparePassword) { + throw this.errorService.createAuthenticationError(this.stringService.authIncorrectPassword); + } + // Compare password const match = await user.comparePassword(password); if (match !== true) { throw this.errorService.createAuthenticationError(this.stringService.authIncorrectPassword); } - + // Remove password from user object. Should this be abstracted to DB layer? const userWithoutPassword = { ...user._doc }; delete userWithoutPassword.password; @@ -103,6 +109,15 @@ class UserService { userWithoutPassword.avatarImage = user.avatarImage; return { user: userWithoutPassword, token }; } catch (error) { + // Log specific errors while returning generic message for security + this.logger.error({ + message: "Login attempt failed", + service: SERVICE_NAME, + method: "loginUser", + error: error.message, + stack: error.stack, + }); + // If user is not found, throw a generic authentication error for security // Don't reveal whether user exists or password is wrong throw this.errorService.createAuthenticationError(this.stringService.authIncorrectPassword); @@ -117,6 +132,12 @@ class UserService { updates.email = currentUser.email; // Get user const user = await this.db.userModule.getUserByEmail(currentUser.email); + + // Add null check before password comparison + if (!user || !user.comparePassword) { + throw this.errorService.createAuthorizationError(this.stringService.authIncorrectPassword); + } + // Compare passwords const match = await user.comparePassword(updates?.password); // If not a match, throw a 403 diff --git a/server/src/utils/imageProcessing.js b/server/src/utils/imageProcessing.js index 470a5c27e..2e1895923 100755 --- a/server/src/utils/imageProcessing.js +++ b/server/src/utils/imageProcessing.js @@ -1,21 +1,12 @@ -import sharp from "sharp"; /** - * Generates a 64 * 64 pixel image from a given image + * Converts image to base64 string without resizing + * CSS handles the 64x64 display sizing client-side * @param {} file */ const GenerateAvatarImage = async (file) => { try { - // Resize to target 64 * 64 - let resizedImageBuffer = await sharp(file.buffer) - .resize({ - width: 64, - height: 64, - fit: "cover", - }) - .toBuffer(); - - //Get b64 string - const base64Image = resizedImageBuffer.toString("base64"); + // Simply convert to base64 - let CSS handle the 64x64 display + const base64Image = file.buffer.toString("base64"); return base64Image; } catch (error) { throw error;