Skip to content

Commit f5c3290

Browse files
authored
Make Argon2 WebAssembly module unload after use (#5072)
1 parent 3185c0a commit f5c3290

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

libs/common/src/platform/services/web-crypto-function.service.ts

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export class WebCryptoFunctionService implements CryptoFunctionService {
6969
hashLen: 32,
7070
type: argon2.ArgonType.Argon2id,
7171
});
72+
argon2.unloadRuntime();
7273
return result.hash;
7374
}
7475

patches/argon2-browser+1.18.0.patch

+14-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
diff --git a/node_modules/argon2-browser/lib/argon2.js b/node_modules/argon2-browser/lib/argon2.js
2-
index ffa77a5..b498e2d 100644
2+
index ffa77a5..98b2f13 100644
33
--- a/node_modules/argon2-browser/lib/argon2.js
44
+++ b/node_modules/argon2-browser/lib/argon2.js
55
@@ -78,16 +78,27 @@
@@ -36,10 +36,16 @@ index ffa77a5..b498e2d 100644
3636
return fetch(wasmPath)
3737
.then((response) => response.arrayBuffer())
3838
.then((ab) => new Uint8Array(ab));
39-
@@ -354,6 +365,24 @@
40-
}
41-
}
42-
39+
@@ -351,7 +362,28 @@
40+
loadModule._module.unloadRuntime();
41+
delete loadModule._promise;
42+
delete loadModule._module;
43+
+ if (typeof require !== 'undefined') {
44+
+ delete require.cache[require.resolve('../dist/argon2.js')]
45+
+ }
46+
+ }
47+
+ }
48+
+
4349
+ // ref: https://stackoverflow.com/a/47880734/1090359
4450
+ // ref: https://github.com/GoogleChromeLabs/wasm-feature-detect/blob/main/src/detectors/simd/module.wat (translated with wat2wasm)
4551
+ function checkIfSIMDSupported() {
@@ -54,10 +60,8 @@ index ffa77a5..b498e2d 100644
5460
+ }
5561
+ } catch {
5662
+ return false;
57-
+ }
63+
}
5864
+ return false;
59-
+ }
60-
+
65+
}
66+
6167
return {
62-
ArgonType,
63-
hash: argon2Hash,

0 commit comments

Comments
 (0)