Skip to content

Commit ff1b92f

Browse files
authored
chore: replace insecure randomness and fix alert (#197)
2 parents a7fbd12 + f65b355 commit ff1b92f

File tree

1 file changed

+1
-25
lines changed

1 file changed

+1
-25
lines changed

frontend/src/components/Upload/Upload.helpers.ts

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,6 @@ import axios from 'axios';
22

33
import { getPresignedUrl } from '../../helpers/API';
44

5-
export const generateUUID = (): string => {
6-
let d = new Date().getTime(); //Timestamp
7-
let d2 =
8-
(typeof performance !== 'undefined' &&
9-
performance.now &&
10-
performance.now() * 1000) ||
11-
0; //Time in microseconds since page-load or 0 if unsupported
12-
13-
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
14-
let r = Math.random() * 16; //random number between 0 and 16
15-
if (d > 0) {
16-
//Use timestamp until depleted
17-
r = ((d + r) % 16) | 0;
18-
d = Math.floor(d / 16);
19-
} else {
20-
//Use microseconds since page-load if supported
21-
r = ((d2 + r) % 16) | 0;
22-
d2 = Math.floor(d2 / 16);
23-
}
24-
25-
return (c === 'x' ? r : (r & 0x3) | 0x8).toString(16);
26-
});
27-
};
28-
295
export type FileWithUrl = {
306
id: string;
317
url?: string;
@@ -52,7 +28,7 @@ export const generateUploadUrls = async (
5228
status: 'ready',
5329
});
5430
} else {
55-
const localUUID = generateUUID();
31+
const localUUID = self.crypto.randomUUID();
5632
newFileUploadData.set(localUUID, {
5733
id: localUUID,
5834
file: acceptedFiles[idx],

0 commit comments

Comments
 (0)