From 9e8033e36e91273072a5bdfc8639ec531cf4ddfa Mon Sep 17 00:00:00 2001 From: Ashwini Kammar Date: Fri, 15 May 2020 10:51:01 +0100 Subject: [PATCH] Fixing thelounge username case-sensitivity - issue#2943 Removing the duplicate user profiles --- src/clientManager.js | 26 ++++++++++++++++++++++++-- src/server.js | 4 ++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/clientManager.js b/src/clientManager.js index ca1f55b6..36df055c 100644 --- a/src/clientManager.js +++ b/src/clientManager.js @@ -34,18 +34,40 @@ ClientManager.prototype.init = function (identHandler, sockets) { }; ClientManager.prototype.findClient = function (name) { - return this.clients.find((u) => u.name === name); + name = name.toLowerCase(); + return this.clients.find((u) => u.name.toLowerCase() === name); }; ClientManager.prototype.loadUsers = function () { - const users = this.getUsers(); + let users = this.getUsers(); if (users.length === 0) { log.info( `There are currently no users. Create one with ${colors.bold("thelounge add ")}.` ); + + return; } + const alreadySeenUsers = new Set(); + users = users.filter((user) => { + user = user.toLowerCase(); + + if (alreadySeenUsers.has(user)) { + log.error( + `There is more than one user named "${colors.bold( + user + )}". Usernames are now case insensitive, duplicate users will not load.` + ); + + return false; + } + + alreadySeenUsers.add(user); + + return true; + }); + // This callback is used by Auth plugins to load users they deem acceptable const callbackLoadUser = (user) => { this.loadUser(user); diff --git a/src/server.js b/src/server.js index ba1ab417..699cabb8 100644 --- a/src/server.js +++ b/src/server.js @@ -803,6 +803,10 @@ function performAuthentication(data) { return; } + if (typeof data.user !== "string") { + return; + } + const authCallback = (success) => { // Authorization failed if (!success) {