From 8e2a296181b0bebf6ed41f7dae67e6afeaa70cb8 Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 16 Jan 2025 15:17:08 +0000 Subject: [PATCH] Switch to secure random strings Because the js-sdk methods are changing and there's no reason for these not to use the secure versions. The dedicated upper/lower functions were *only* used in this one case, so this should do the exact same thing with the one exported function. Requires https://github.com/matrix-org/matrix-js-sdk/pull/4621 (merge both together) --- src/utils/WidgetUtils.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/utils/WidgetUtils.ts b/src/utils/WidgetUtils.ts index d9de59e4013..7ff1886511c 100644 --- a/src/utils/WidgetUtils.ts +++ b/src/utils/WidgetUtils.ts @@ -14,7 +14,7 @@ import { Room, ClientEvent, MatrixClient, RoomStateEvent, MatrixEvent } from "ma import { KnownMembership } from "matrix-js-sdk/src/types"; import { logger } from "matrix-js-sdk/src/logger"; import { CallType } from "matrix-js-sdk/src/webrtc/call"; -import { randomString, randomLowercaseString, randomUppercaseString } from "matrix-js-sdk/src/randomstring"; +import { LOWERCASE, secureRandomString, secureRandomStringFrom } from "matrix-js-sdk/src/randomstring"; import PlatformPeg from "../PlatformPeg"; import SdkConfig from "../SdkConfig"; @@ -30,6 +30,7 @@ import { parseUrl } from "./UrlUtils"; import { useEventEmitter } from "../hooks/useEventEmitter"; import { WidgetLayoutStore } from "../stores/widgets/WidgetLayoutStore"; import { IWidgetEvent, UserWidget } from "./WidgetUtils-types"; +import { capitalize } from "lodash"; // How long we wait for the state event echo to come back from the server // before waitFor[Room/User]Widget rejects its promise @@ -427,7 +428,10 @@ export default class WidgetUtils { ): Promise { const domain = Jitsi.getInstance().preferredDomain; const auth = (await Jitsi.getInstance().getJitsiAuth()) ?? undefined; - const widgetId = randomString(24); // Must be globally unique + + // Must be globally unique, although predicatablity is not important, the js-sdk has functions to generate + // secure ranom strings, and speed is not important here. + const widgetId = secureRandomString(24); let confId: string; if (auth === "openidtoken-jwt") { @@ -437,8 +441,8 @@ export default class WidgetUtils { // https://github.com/matrix-org/prosody-mod-auth-matrix-user-verification confId = base32.stringify(new TextEncoder().encode(roomId), { pad: false }); } else { - // Create a random conference ID - confId = `Jitsi${randomUppercaseString(1)}${randomLowercaseString(23)}`; + // Create a random conference ID (capitalised so the name looks sensible in Jitsi) + confId = `Jitsi${capitalize(secureRandomStringFrom(24, LOWERCASE))}`; } // TODO: Remove URL hacks when the mobile clients eventually support v2 widgets