Skip to content

Commit

Permalink
fix: weak cryptography
Browse files Browse the repository at this point in the history
  • Loading branch information
seeratawan01 committed Oct 16, 2024
1 parent b1db4ab commit 1a430ca
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/javascript-sdk/src/core/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class UsermavenClient {
this.config.maxSendAttempts || 3,
this.config.minSendTimeout || 1000,
10,
500 // Reduced interval to .5 second
200 // Reduced interval to .2 second
);

if (isWindowAvailable()) {
Expand Down
8 changes: 6 additions & 2 deletions packages/javascript-sdk/src/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,12 @@ export function isWindowAvailable(): boolean {
}


export function generateRandom(): string {
return Math.random().toString(36).substring(2, 7)
export function generateRandom(length: number = 5): string {
const array = new Uint8Array(length);
crypto.getRandomValues(array);
return Array.from(array, (byte) => byte.toString(36).padStart(2, '0'))
.join('')
.slice(0, length);
}

export function toCamelCase(str: string): string {
Expand Down
3 changes: 2 additions & 1 deletion packages/javascript-sdk/src/utils/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {LogLevel} from "../utils/logger";
import {generateRandom} from "../utils/common";

export function generateId(): string {
return Math.random().toString(36).substring(2, 12);
return generateRandom(10);
}

export function isValidEmail(email: string): boolean {
Expand Down

0 comments on commit 1a430ca

Please sign in to comment.