From ef7ae15722dfaa7d6d8370c2915552c13357972c Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Wed, 25 Nov 2020 17:17:26 -0500 Subject: [PATCH] PadMessageHandler: Don't send USER_NEWINFO about unknown authors When a new client opens a socket.io connection and sends a CLIENT_READY message, Etherpad sends the new client a bunch of USER_NEWINFO messages, one per other user already connected to the pad. When iterating over the other users, filter out those without an author ID or missing from the global authors database. --- src/node/handler/PadMessageHandler.js | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/node/handler/PadMessageHandler.js b/src/node/handler/PadMessageHandler.js index 214571044..84ec9b5c1 100644 --- a/src/node/handler/PadMessageHandler.js +++ b/src/node/handler/PadMessageHandler.js @@ -1124,20 +1124,25 @@ async function handleClientReady(socket, message, authorID) { if (sessionInfo == null) return; // get the authorname & colorId - const author = sessionInfo.author; - const cached = historicalAuthorData[author]; + const authorId = sessionInfo.author; + // The authorId of this other user might be unknown if the other user just connected and has + // not yet sent a CLIENT_READY message. + if (authorId == null) return; // reuse previously created cache of author's data - let authorInfo = cached ? cached : (await authorManager.getAuthor(author)); + const authorInfo = historicalAuthorData[authorId] || await authorManager.getAuthor(authorId); + if (authorInfo == null) { + messageLogger.error( + `Author ${authorId} connected via socket.io session ${roomSocket.id} is missing from ` + + 'the global author database. This should never happen because the author ID is ' + + 'generated by the same code that adds the author to the database.'); + // Don't bother telling the new user about this mystery author. + return; + } // default fallback color to use if authorInfo.colorId is null const defaultColor = '#daf0b2'; - if (!authorInfo) { - console.warn('handleClientReady(): no authorInfo parameter was received. Default values are going to be used. See issue #3612. This can be caused by a user clicking undo after clearing all authorship colors see #2802'); - authorInfo = {}; - } - // For some reason sometimes name isn't set // Catch this issue here and use a fixed name. if (!authorInfo.name) { @@ -1162,7 +1167,7 @@ async function handleClientReady(socket, message, authorID) { colorId: authorInfo.colorId, name: authorInfo.name, userAgent: 'Anonymous', - userId: author, + userId: authorId, }, }, };