From 332feefa369b7420036cbc7fb938a3f125e603a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Fri, 28 Jan 2022 11:26:24 +0100 Subject: [PATCH] fix(util) never mark UUID room names as insecure Except the NIL UUID, that is. --- .../features/base/util/isInsecureRoomName.js | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/react/features/base/util/isInsecureRoomName.js b/react/features/base/util/isInsecureRoomName.js index 1b7914de3e..c6edec7341 100644 --- a/react/features/base/util/isInsecureRoomName.js +++ b/react/features/base/util/isInsecureRoomName.js @@ -1,7 +1,30 @@ // @flow +import _ from 'lodash'; +import { NIL, parse as parseUUID } from 'uuid'; import zxcvbn from 'zxcvbn'; +// The null UUID. +const NIL_UUID = parseUUID(NIL); + +/** + * Checks if the given string is a valid UUID or not. + * + * @param {string} str - The string to be checked. + * @returns {boolean} - Whether the string is a valid UUID or not. + */ +function isValidUUID(str) { + let uuid; + + try { + uuid = parseUUID(str); + } catch (e) { + return false; + } + + return !_.isEqual(uuid, NIL_UUID); +} + /** * Returns true if the room name is considered a weak (insecure) one. * @@ -9,5 +32,5 @@ import zxcvbn from 'zxcvbn'; * @returns {boolean} */ export default function isInsecureRoomName(roomName: string = ''): boolean { - return zxcvbn(roomName).score < 3; + return !isValidUUID(roomName) && zxcvbn(roomName).score < 3; }