Skip to content

Commit 9829236

Browse files
Fix code scanning alert no. 2: Insecure randomness
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent 833a662 commit 9829236

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

test/utils.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
'use strict';
22

3+
const crypto = require('crypto');
4+
35
function getRandomString(text){
4-
return text + Math.floor((Math.random() * 100000) + 1);
6+
const randomInt = crypto.randomBytes(4).readUInt32BE(0) % 100000 + 1;
7+
return text + randomInt;
58
}
69

710
function getRandomInt(){
8-
return Math.floor((Math.random() * 100000) + 1);
11+
return crypto.randomBytes(4).readUInt32BE(0) % 100000 + 1;
912
}
1013

1114
function getRandomAmount(){
12-
return ((Math.random() * 1000) + 1).toFixed(2);
15+
const randomFloat = crypto.randomBytes(4).readUInt32BE(0) / 0xFFFFFFFF;
16+
return ((randomFloat * 1000) + 1).toFixed(2);
1317
}
1418

1519
function getDate(){

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy