mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-05 11:51:16 -06:00
replace Math.random with crypto random function
This commit is contained in:
@@ -1,5 +1,16 @@
|
||||
export function withClientRequestState(obj) {
|
||||
obj.state = Math.random().toString(36).substring(7);
|
||||
obj.state = generateState(16);
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
function dec2hex (dec) {
|
||||
return dec.toString(16).padStart(2, "0")
|
||||
}
|
||||
|
||||
// generateState :: Integer -> String
|
||||
function generateState (len) {
|
||||
var arr = new Uint8Array((len || 16) / 2)
|
||||
window.crypto.getRandomValues(arr)
|
||||
return Array.from(arr, dec2hex).join('')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user