2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-14 18:42:33 +03:00

fix(utils): replace getRandomValues with crypto module (#6788)

This commit is contained in:
Willian Agostini
2025-02-18 09:36:51 -03:00
committed by GitHub
parent 32c7bcc0f2
commit 23a25af068
2 changed files with 25 additions and 2 deletions
+5 -2
View File
@@ -1,6 +1,7 @@
'use strict';
import bind from './helpers/bind.js';
import crypto from 'crypto';
// utils is a library of generic helper functions non-specific to axios
@@ -615,8 +616,10 @@ const ALPHABET = {
const generateString = (size = 16, alphabet = ALPHABET.ALPHA_DIGIT) => {
let str = '';
const {length} = alphabet;
while (size--) {
str += alphabet[Math.random() * length|0]
const randomValues = new Uint32Array(size);
crypto.randomFillSync(randomValues);
for (let i = 0; i < size; i++) {
str += alphabet[randomValues[i] % length];
}
return str;