Skip to content

Commit c726eb7

Browse files
committed
fix secure random
1 parent ad4ef4f commit c726eb7

File tree

5 files changed

+10
-10
lines changed

5 files changed

+10
-10
lines changed

src/auth/useRecaptcha.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Please see LICENSE in the repository root for full details.
66
*/
77

88
import { useEffect, useCallback, useRef, useState } from "react";
9-
import { randomString } from "matrix-js-sdk/src/randomstring";
9+
import { secureRandomString } from "matrix-js-sdk/src/randomstring";
1010
import { useTranslation } from "react-i18next";
1111
import { logger } from "matrix-js-sdk/src/logger";
1212

@@ -31,7 +31,7 @@ export function useRecaptcha(sitekey?: string): {
3131
recaptchaId: string;
3232
} {
3333
const { t } = useTranslation();
34-
const [recaptchaId] = useState(() => randomString(16));
34+
const [recaptchaId] = useState(() => secureRandomString(16));
3535
const promiseRef = useRef<RecaptchaPromiseRef | undefined>(undefined);
3636

3737
useEffect(() => {

src/auth/useRegisterPasswordlessUser.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Please see LICENSE in the repository root for full details.
66
*/
77

88
import { useCallback } from "react";
9-
import { randomString } from "matrix-js-sdk/src/randomstring";
9+
import { secureRandomString } from "matrix-js-sdk/src/randomstring";
1010

1111
import { useClient } from "../ClientContext";
1212
import { useInteractiveRegistration } from "../auth/useInteractiveRegistration";
@@ -42,7 +42,7 @@ export function useRegisterPasswordlessUser(): UseRegisterPasswordlessUserType {
4242
const userName = generateRandomName();
4343
const [client, session] = await register(
4444
userName,
45-
randomString(16),
45+
secureRandomString(16),
4646
displayName,
4747
recaptchaResponse,
4848
true,

src/home/UnauthenticatedView.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Please see LICENSE in the repository root for full details.
66
*/
77

88
import { type FC, useCallback, useState, type FormEventHandler } from "react";
9-
import { randomString } from "matrix-js-sdk/src/randomstring";
9+
import { secureRandomString } from "matrix-js-sdk/src/randomstring";
1010
import { Trans, useTranslation } from "react-i18next";
1111
import { Button, Heading, Text } from "@vector-im/compound-web";
1212
import { logger } from "matrix-js-sdk/src/logger";
@@ -67,7 +67,7 @@ export const UnauthenticatedView: FC = () => {
6767
const userName = generateRandomName();
6868
const [client, session] = await register(
6969
userName,
70-
randomString(16),
70+
secureRandomString(16),
7171
displayName,
7272
recaptchaResponse,
7373
true,

src/settings/FeedbackSettingsTab.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Please see LICENSE in the repository root for full details.
66
*/
77

88
import { type ChangeEvent, type FC, useCallback } from "react";
9-
import { randomString } from "matrix-js-sdk/src/randomstring";
9+
import { secureRandomString } from "matrix-js-sdk/src/randomstring";
1010
import { Trans, useTranslation } from "react-i18next";
1111
import { Button, Text } from "@vector-im/compound-web";
1212
import { logger } from "matrix-js-sdk/src/logger";
@@ -36,7 +36,7 @@ export const FeedbackSettingsTab: FC<Props> = ({ roomId }) => {
3636
const description =
3737
typeof descriptionData === "string" ? descriptionData : "";
3838
const sendLogs = Boolean(data.get("sendLogs"));
39-
const rageshakeRequestId = randomString(16);
39+
const rageshakeRequestId = secureRandomString(16);
4040

4141
submitRageshake({
4242
description,

src/settings/rageshake.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Please see LICENSE in the repository root for full details.
3030
import EventEmitter from "events";
3131
import { throttle } from "lodash-es";
3232
import { type Logger, logger } from "matrix-js-sdk/src/logger";
33-
import { randomString } from "matrix-js-sdk/src/randomstring";
33+
import { secureRandomString } from "matrix-js-sdk/src/randomstring";
3434
import { type LoggingMethod } from "loglevel";
3535

3636
import type loglevel from "loglevel";
@@ -128,7 +128,7 @@ class IndexedDBLogStore {
128128
private indexedDB: IDBFactory,
129129
private loggerInstance: ConsoleLogger,
130130
) {
131-
this.id = "instance-" + randomString(16);
131+
this.id = "instance-" + secureRandomString(16);
132132

133133
loggerInstance.on(ConsoleLoggerEvent.Log, this.onLoggerLog);
134134
window.addEventListener("beforeunload", () => {

0 commit comments

Comments
 (0)