Skip to content

Commit 1e965b1

Browse files
authored
Merge pull request #2378 from ViewComponent/alert-autofix-17
Potential fix for code scanning alert no. 17: Insecure randomness
2 parents 6dd24c7 + 15b80fb commit 1e965b1

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

test/sandbox/public/turbo.es2017-esm.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,16 +499,17 @@ function interpolate(strings, values) {
499499
}
500500

501501
function uuid() {
502+
const randomValues = crypto.getRandomValues(new Uint8Array(36));
502503
return Array.from({ length: 36 })
503504
.map((_, i) => {
504505
if (i == 8 || i == 13 || i == 18 || i == 23) {
505506
return "-"
506507
} else if (i == 14) {
507508
return "4"
508509
} else if (i == 19) {
509-
return (Math.floor(Math.random() * 4) + 8).toString(16)
510+
return ((randomValues[i] % 4) + 8).toString(16)
510511
} else {
511-
return Math.floor(Math.random() * 15).toString(16)
512+
return (randomValues[i] % 16).toString(16)
512513
}
513514
})
514515
.join("")

0 commit comments

Comments
 (0)