1
0
mirror of https://github.com/bitwarden/browser synced 2024-12-22 07:57:01 +01:00

Make Argon2 WebAssembly module unload after use (#5072)

This commit is contained in:
Bernd Schoolmann 2023-07-03 14:12:42 +02:00 committed by GitHub
parent 3185c0a61b
commit f5c329030d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 10 deletions

View File

@ -69,6 +69,7 @@ export class WebCryptoFunctionService implements CryptoFunctionService {
hashLen: 32,
type: argon2.ArgonType.Argon2id,
});
argon2.unloadRuntime();
return result.hash;
}

View File

@ -1,5 +1,5 @@
diff --git a/node_modules/argon2-browser/lib/argon2.js b/node_modules/argon2-browser/lib/argon2.js
index ffa77a5..b498e2d 100644
index ffa77a5..98b2f13 100644
--- a/node_modules/argon2-browser/lib/argon2.js
+++ b/node_modules/argon2-browser/lib/argon2.js
@@ -78,16 +78,27 @@
@ -36,10 +36,16 @@ index ffa77a5..b498e2d 100644
return fetch(wasmPath)
.then((response) => response.arrayBuffer())
.then((ab) => new Uint8Array(ab));
@@ -354,6 +365,24 @@
}
}
@@ -351,7 +362,28 @@
loadModule._module.unloadRuntime();
delete loadModule._promise;
delete loadModule._module;
+ if (typeof require !== 'undefined') {
+ delete require.cache[require.resolve('../dist/argon2.js')]
+ }
+ }
+ }
+
+ // ref: https://stackoverflow.com/a/47880734/1090359
+ // ref: https://github.com/GoogleChromeLabs/wasm-feature-detect/blob/main/src/detectors/simd/module.wat (translated with wat2wasm)
+ function checkIfSIMDSupported() {
@ -54,10 +60,8 @@ index ffa77a5..b498e2d 100644
+ }
+ } catch {
+ return false;
+ }
}
+ return false;
+ }
+
}
return {
ArgonType,
hash: argon2Hash,