Skip to content

Commit

Permalink
Update generateUuid function to use crypto library fixed: #483 (#548)
Browse files Browse the repository at this point in the history
Replaced Math.random with crypto.getRandomValues for secure UUID
generation.
  • Loading branch information
chavda-bhavik authored Apr 24, 2024
2 parents 98f846b + cc6bc30 commit 34407ef
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/react/src/hooks/useImpler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,14 @@ export function useImpler({
}, []);

function generateUuid() {
return Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
}
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (cv) {
const cr = crypto.getRandomValues(new Uint8Array(1))[0] % 16 | 0;
const vv = cv === 'x' ? cr : (cr & 0x3) | 0x8;

return vv.toString(16);
});
}

const showWidget = async ({ colorScheme, data, schema, output }: ShowWidgetProps) => {
if (window.impler && isImplerInitiated) {
const payload: IShowPayload = {
Expand Down

0 comments on commit 34407ef

Please sign in to comment.