Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@
"buffer": "^6.0.3",
"copy-webpack-plugin": "^11.0.0",
"idb-keyval": "^6.2.0",
"lodash": "^4.17.21",
"qs": "^6.12.3",
"throttle-debounce": "^3.0.1",
"uuid": "^9.0.0",
"yup": "^0.32.9"
},
"scripts": {
Expand Down Expand Up @@ -74,7 +72,6 @@
"@types/jest": "^28.1.1",
"@types/node": "^12.12.6",
"@types/throttle-debounce": "^2.1.0",
"@types/uuid": "^9.0.8",
"@typescript-eslint/eslint-plugin": "^5.38.1",
"@typescript-eslint/parser": "^5.38.1",
"@webpack-cli/serve": "^1.6.0",
Expand Down
4 changes: 2 additions & 2 deletions src/embedded/embeddedSessionManager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-param-reassign */
/* eslint-disable class-methods-use-this */
import { v4 as uuidv4 } from 'uuid';
import { generateUUID } from '../utils/generateUUID';
import { trackEmbeddedSession } from '../events/embedded/events';
import { IterableEmbeddedSessionRequestPayload } from '..';

Expand All @@ -14,7 +14,7 @@ class EmbeddedSession {
constructor(start?: Date, end?: Date) {
this.start = start;
this.end = end;
this.id = uuidv4();
this.id = generateUUID();
}
}

Expand Down
9 changes: 7 additions & 2 deletions src/inapp/inapp.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable consistent-return */
/* eslint-disable no-param-reassign */
/* eslint-disable no-redeclare */
import set from 'lodash/set';
import { throttle } from 'throttle-debounce';
import {
ABSOLUTE_DISMISS_BUTTON_ID,
Expand Down Expand Up @@ -685,7 +684,13 @@ export function getInAppMessages(
const withIframes = messages?.map((message) => {
const html = message.content?.html;
return html
? set(message, 'content.html', wrapWithIFrame(html as string))
? {
...message,
content: {
...message.content,
html: wrapWithIFrame(html as string)
}
}
: message;
});
return {
Expand Down
4 changes: 2 additions & 2 deletions src/unknownUserTracking/unknownUserEventManager.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable class-methods-use-this */
import { v4 as uuidv4 } from 'uuid';
import { generateUUID } from '../utils/generateUUID';
import {
UpdateCartRequestParams,
TrackPurchaseRequestParams,
Expand Down Expand Up @@ -263,7 +263,7 @@

delete dataFields[SHARED_PREFS_EVENT_TYPE];

const userId = uuidv4();
const userId = generateUUID();

Check failure

Code scanning / CodeQL

Insecure randomness High

This uses a cryptographically insecure random number generated at
Math.random()
in a security context.

if (userData) {
const userSessionInfo = JSON.parse(userData);
Expand Down
12 changes: 12 additions & 0 deletions src/utils/generateUUID.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* eslint-disable no-bitwise */
export function generateUUID(): string {
if (typeof crypto !== 'undefined' && crypto.randomUUID) {
return crypto.randomUUID();
}
// Fallback for environments without crypto.randomUUID (e.g. Node 18)
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
const r = (Math.random() * 16) | 0;
const v = c === 'x' ? r : (r & 0x3) | 0x8;
return v.toString(16);
});
}
10 changes: 0 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1741,11 +1741,6 @@
resolved "https://registry.yarnpkg.com/@types/tough-cookie/-/tough-cookie-4.0.5.tgz#cb6e2a691b70cb177c6e3ae9c1d2e8b2ea8cd304"
integrity sha512-/Ad8+nIOV7Rl++6f1BdKxFSMgmoqEoYbHRpPcx3JEfv8VRsQe9Z4mCXeJBzxs7mbHY/XOZZuXlRNfhpVPbs6ZA==

"@types/uuid@^9.0.8":
version "9.0.8"
resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-9.0.8.tgz#7545ba4fc3c003d6c756f651f3bf163d8f0f29ba"
integrity sha512-jg+97EGIcY9AGHJJRaaPVgetKDsrTgbRjQ5Msgjh/DQKEFl0DtyRr/VCOyD1T2R1MNeWPK/u7JoGhlDZnKBAfA==

"@types/ws@8.5.4":
version "8.5.4"
resolved "https://registry.yarnpkg.com/@types/ws/-/ws-8.5.4.tgz#bb10e36116d6e570dd943735f86c933c1587b8a5"
Expand Down Expand Up @@ -7631,11 +7626,6 @@ uuid@^8.3.2:
resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2"
integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==

uuid@^9.0.0:
version "9.0.1"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-9.0.1.tgz#e188d4c8853cc722220392c424cd637f32293f30"
integrity sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==

v8-to-istanbul@^9.0.1:
version "9.3.0"
resolved "https://registry.yarnpkg.com/v8-to-istanbul/-/v8-to-istanbul-9.3.0.tgz#b9572abfa62bd556c16d75fdebc1a411d5ff3175"
Expand Down
Loading