Skip to content

Commit

Permalink
Merge pull request #9 from athrael-soju/alert-autofix-3
Browse files Browse the repository at this point in the history
Fix code scanning alert no. 3: Insecure randomness
  • Loading branch information
athrael-soju authored Dec 19, 2024
2 parents 2d8f356 + f4d0971 commit 2aefa06
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ export function getLocalStorage(key: string) {
return [];
}

import { randomBytes } from 'crypto';

export function generateUUID(): string {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
const r = (Math.random() * 16) | 0;
const r = randomBytes(1)[0] % 16;
const v = c === 'x' ? r : (r & 0x3) | 0x8;
return v.toString(16);
});
Expand Down

0 comments on commit 2aefa06

Please sign in to comment.