Skip to content

Commit

Permalink
Switch to secure random strings
Browse files Browse the repository at this point in the history
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 matrix-org/matrix-js-sdk#4621 (merge both together)
  • Loading branch information
dbkr committed Jan 16, 2025
1 parent 58f812f commit 8e2a296
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/utils/WidgetUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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";

Check failure on line 32 in src/utils/WidgetUtils.ts

View workflow job for this annotation

GitHub Actions / ESLint

There should be at least one empty line between import groups
import { capitalize } from "lodash";

Check failure on line 33 in src/utils/WidgetUtils.ts

View workflow job for this annotation

GitHub Actions / ESLint

`lodash` import should occur before import of `../PlatformPeg`

// How long we wait for the state event echo to come back from the server
// before waitFor[Room/User]Widget rejects its promise
Expand Down Expand Up @@ -427,7 +428,10 @@ export default class WidgetUtils {
): Promise<void> {
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") {
Expand All @@ -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
Expand Down

0 comments on commit 8e2a296

Please sign in to comment.