2022-01-28 10:26:24 +00:00
|
|
|
import _ from 'lodash';
|
|
|
|
import { NIL, parse as parseUUID } from 'uuid';
|
2020-05-18 12:07:09 +00:00
|
|
|
import zxcvbn from 'zxcvbn';
|
|
|
|
|
2022-01-28 10:26:24 +00:00
|
|
|
// 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.
|
|
|
|
*/
|
2022-07-29 13:18:14 +00:00
|
|
|
function isValidUUID(str: string) {
|
2022-01-28 10:26:24 +00:00
|
|
|
let uuid;
|
|
|
|
|
|
|
|
try {
|
|
|
|
uuid = parseUUID(str);
|
|
|
|
} catch (e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return !_.isEqual(uuid, NIL_UUID);
|
|
|
|
}
|
|
|
|
|
2020-05-18 12:07:09 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the room name is considered a weak (insecure) one.
|
|
|
|
*
|
|
|
|
* @param {string} roomName - The room name.
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2022-07-29 13:18:14 +00:00
|
|
|
export default function isInsecureRoomName(roomName = ''): boolean {
|
2022-01-28 10:26:24 +00:00
|
|
|
return !isValidUUID(roomName) && zxcvbn(roomName).score < 3;
|
2020-05-18 12:07:09 +00:00
|
|
|
}
|