mirror of
https://github.com/nextcloud/server.git
synced 2026-06-10 17:23:59 -04:00
Merge pull request #53635 from nextcloud/fix/insecure-crypto-envs
fix(files_sharing): fallback self.crypto.getRandomValues
This commit is contained in:
commit
33ddce490b
9 changed files with 32 additions and 13 deletions
|
|
@ -38,10 +38,29 @@ export default async function(verbose = false): Promise<string> {
|
|||
|
||||
const array = new Uint8Array(10)
|
||||
const ratio = passwordSet.length / 255
|
||||
self.crypto.getRandomValues(array)
|
||||
getRandomValues(array)
|
||||
let password = ''
|
||||
for (let i = 0; i < array.length; i++) {
|
||||
password += passwordSet.charAt(array[i] * ratio)
|
||||
}
|
||||
return password
|
||||
}
|
||||
|
||||
/**
|
||||
* Fills the given array with cryptographically secure random values.
|
||||
* If the crypto API is not available, it falls back to less secure Math.random().
|
||||
* Crypto API is available in modern browsers on secure contexts (HTTPS).
|
||||
*
|
||||
* @param {Uint8Array} array - The array to fill with random values.
|
||||
*/
|
||||
function getRandomValues(array: Uint8Array): void {
|
||||
if (self?.crypto?.getRandomValues) {
|
||||
self.crypto.getRandomValues(array)
|
||||
return
|
||||
}
|
||||
|
||||
let len = array.length
|
||||
while (len--) {
|
||||
array[len] = Math.floor(Math.random() * 256)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
4
dist/519-519.js
vendored
4
dist/519-519.js
vendored
File diff suppressed because one or more lines are too long
2
dist/519-519.js.map
vendored
2
dist/519-519.js.map
vendored
File diff suppressed because one or more lines are too long
4
dist/5792-5792.js
vendored
4
dist/5792-5792.js
vendored
File diff suppressed because one or more lines are too long
2
dist/5792-5792.js.map
vendored
2
dist/5792-5792.js.map
vendored
File diff suppressed because one or more lines are too long
4
dist/files_sharing-files_sharing_tab.js
vendored
4
dist/files_sharing-files_sharing_tab.js
vendored
File diff suppressed because one or more lines are too long
2
dist/files_sharing-files_sharing_tab.js.map
vendored
2
dist/files_sharing-files_sharing_tab.js.map
vendored
File diff suppressed because one or more lines are too long
4
dist/files_sharing-init.js
vendored
4
dist/files_sharing-init.js
vendored
File diff suppressed because one or more lines are too long
2
dist/files_sharing-init.js.map
vendored
2
dist/files_sharing-init.js.map
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue