From e2937ffa5028228f06e5e090010d7df85d6dfbd7 Mon Sep 17 00:00:00 2001 From: H_S <81474463+HarjobandeepSingh@users.noreply.github.com> Date: Fri, 19 Apr 2024 20:16:53 +0530 Subject: [PATCH] Update generateUuid function to use crypto library Replaced Math.random with crypto.getRandomValues for secure UUID generation. Ensured each instance of useImpler hook gets a unique UUID. Signed-off-by: H_S <81474463+HarjobandeepSingh@users.noreply.github.com> --- packages/react/src/hooks/useImpler.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/react/src/hooks/useImpler.ts b/packages/react/src/hooks/useImpler.ts index cb97d5b2d..beea94ea4 100644 --- a/packages/react/src/hooks/useImpler.ts +++ b/packages/react/src/hooks/useImpler.ts @@ -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 = {