Skip to content

Commit

Permalink
fix secure random
Browse files Browse the repository at this point in the history
  • Loading branch information
toger5 committed Jan 24, 2025
1 parent da6cb09 commit 578d68d
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/auth/useRecaptcha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Please see LICENSE in the repository root for full details.
*/

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

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

useEffect(() => {
Expand Down
4 changes: 2 additions & 2 deletions src/auth/useRegisterPasswordlessUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Please see LICENSE in the repository root for full details.
*/

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

import { useClient } from "../ClientContext";
import { useInteractiveRegistration } from "../auth/useInteractiveRegistration";
Expand Down Expand Up @@ -42,7 +42,7 @@ export function useRegisterPasswordlessUser(): UseRegisterPasswordlessUserType {
const userName = generateRandomName();
const [client, session] = await register(
userName,
randomString(16),
secureRandomString(16),
displayName,
recaptchaResponse,
true,
Expand Down
4 changes: 2 additions & 2 deletions src/home/UnauthenticatedView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Please see LICENSE in the repository root for full details.
*/

import { type FC, useCallback, useState, type FormEventHandler } from "react";
import { randomString } from "matrix-js-sdk/src/randomstring";
import { secureRandomString } from "matrix-js-sdk/src/randomstring";
import { Trans, useTranslation } from "react-i18next";
import { Button, Heading, Text } from "@vector-im/compound-web";
import { logger } from "matrix-js-sdk/src/logger";
Expand Down Expand Up @@ -67,7 +67,7 @@ export const UnauthenticatedView: FC = () => {
const userName = generateRandomName();
const [client, session] = await register(
userName,
randomString(16),
secureRandomString(16),
displayName,
recaptchaResponse,
true,
Expand Down
4 changes: 2 additions & 2 deletions src/settings/FeedbackSettingsTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Please see LICENSE in the repository root for full details.
*/

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

submitRageshake({
description,
Expand Down
4 changes: 2 additions & 2 deletions src/settings/rageshake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Please see LICENSE in the repository root for full details.
import EventEmitter from "events";
import { throttle } from "lodash-es";
import { type Logger, logger } from "matrix-js-sdk/src/logger";
import { randomString } from "matrix-js-sdk/src/randomstring";
import { secureRandomString } from "matrix-js-sdk/src/randomstring";
import { type LoggingMethod } from "loglevel";

import type loglevel from "loglevel";
Expand Down Expand Up @@ -128,7 +128,7 @@ class IndexedDBLogStore {
private indexedDB: IDBFactory,
private loggerInstance: ConsoleLogger,
) {
this.id = "instance-" + randomString(16);
this.id = "instance-" + secureRandomString(16);

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

0 comments on commit 578d68d

Please sign in to comment.