Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

feat(util): Lazy load the insecure room name checker.

damencho5a11cd8801ce
diff --git a/react/features/base/util/isInsecureRoomName.ts b/react/features/base/util/isInsecureRoomName.ts
index e0feb27f11..76ae00dcc3 100644
--- a/react/features/base/util/isInsecureRoomName.ts
+++ b/react/features/base/util/isInsecureRoomName.ts
@@ -1,11 +1,38 @@
import { isEqual } from 'lodash-es';
import { NIL, parse as parseUUID } from 'uuid';
-import zxcvbn from 'zxcvbn';
// The null UUID.
const NIL_UUID = parseUUID(NIL);
const _zxcvbnCache = new Map();
+let _zxcvbn: ((password: string) => { score: number; }) | null = null;
+
+/**
+ * Triggers the asynchronous load of the zxcvbn library if not already loaded.
+ * Can be called early (e.g. on config load) to ensure the library is ready
+ * before the first call to {@link isInsecureRoomName}.
+ *
+ * @returns {void}
+ */
+export function preloadZxcvbn() {
+ _ensureZxcvbn();
+}
+
+/**
+ * Triggers the asynchronous load of the zxcvbn library if not already loaded.
+ *
+ * @returns {void}
+ */
+function _ensureZxcvbn() {
+ if (_zxcvbn !== null) {
+ return;
+ }
+
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ import(/* webpackChunkName: "zxcvbn" */ 'zxcvbn').then((m: any) => {
+ _zxcvbn = m.default ?? m;
+ });
+}
/**
* Checks if the given string is a valid UUID or not.
@@ -27,16 +54,23 @@ function isValidUUID(str: string) {
/**
* Checks a room name and caches the result.
+ * Returns undefined if zxcvbn is not yet loaded.
*
* @param {string} roomName - The room name.
- * @returns {Object}
+ * @returns {Object|undefined}
*/
function _checkRoomName(roomName = '') {
if (_zxcvbnCache.has(roomName)) {
return _zxcvbnCache.get(roomName);
}
- const result = zxcvbn(roomName);
+ _ensureZxcvbn();
+
+ if (!_zxcvbn) {
+ return undefined;
+ }
+
+ const result = _zxcvbn(roomName);
_zxcvbnCache.set(roomName, result);
@@ -45,6 +79,7 @@ function _checkRoomName(roomName = '') {
/**
* Returns true if the room name is considered a weak (insecure) one.
+ * Returns false (treats as secure) while the zxcvbn library is still loading.
*
* @param {string} roomName - The room name.
* @returns {boolean}
@@ -52,5 +87,5 @@ function _checkRoomName(roomName = '') {
export default function isInsecureRoomName(roomName = ''): boolean {
// room names longer than 200 chars we consider secure
- return !isValidUUID(roomName) && (roomName.length < 200 && _checkRoomName(roomName).score < 3);
+ return !isValidUUID(roomName) && (roomName.length < 200 && (_checkRoomName(roomName)?.score ?? 3) < 3);
}
diff --git a/react/features/prejoin/middleware.web.ts b/react/features/prejoin/middleware.web.ts
index 8f7cfb948b..51bb5d015f 100644
--- a/react/features/prejoin/middleware.web.ts
+++ b/react/features/prejoin/middleware.web.ts
@@ -2,6 +2,7 @@ import { AnyAction } from 'redux';
import { IStore } from '../app/types';
import { CONFERENCE_FAILED, CONFERENCE_JOINED } from '../base/conference/actionTypes';
+import { SET_CONFIG } from '../base/config/actionTypes';
import { CONNECTION_FAILED } from '../base/connection/actionTypes';
import { SET_AUDIO_MUTED, SET_VIDEO_MUTED } from '../base/media/actionTypes';
import MiddlewareRegistry from '../base/redux/MiddlewareRegistry';
@@ -10,13 +11,14 @@ import {
TRACK_ADDED,
TRACK_NO_DATA_FROM_SOURCE
} from '../base/tracks/actionTypes';
+import { preloadZxcvbn } from '../base/util/isInsecureRoomName';
import {
setDeviceStatusOk,
setDeviceStatusWarning,
setJoiningInProgress
} from './actions';
-import { isPrejoinPageVisible } from './functions.any';
+import { isPrejoinPageVisible, isUnsafeRoomWarningEnabled } from './functions.any';
/**
* The redux middleware for {@link PrejoinPage}.
@@ -26,6 +28,15 @@ import { isPrejoinPageVisible } from './functions.any';
*/
MiddlewareRegistry.register(store => next => action => {
switch (action.type) {
+ case SET_CONFIG: {
+ const result = next(action);
+
+ if (isUnsafeRoomWarningEnabled(store.getState())) {
+ preloadZxcvbn();
+ }
+
+ return result;
+ }
case SET_AUDIO_MUTED: {
if (isPrejoinPageVisible(store.getState())) {
store.dispatch(updateSettings({
diff --git a/tsconfig.native.json b/tsconfig.native.json
index 0b1432f4d0..493291a545 100644
--- a/tsconfig.native.json
+++ b/tsconfig.native.json
@@ -2,6 +2,7 @@
"include": ["react/features/**/*.ts", "react/features/**/*.tsx", "./custom.d.ts", "./globals.native.d.ts"],
"compilerOptions": {
"allowSyntheticDefaultImports": true,
+ "module": "es2020",
"target": "es2020",
"jsx": "react-native",
"lib": [ "ES2020", "ES2024.Promise" ],
diff --git a/webpack.config.js b/webpack.config.js
index abeb8dead9..e5f085828d 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -345,7 +345,7 @@ module.exports = (_env, argv) => {
})
],
- performance: getPerformanceHints(perfHintOptions, 5 * 1024 * 1024) },
+ performance: getPerformanceHints(perfHintOptions, 3.5 * 1024 * 1024) },
{ ...config,
entry: {
'alwaysontop': './react/features/always-on-top/index.tsx'