Browse Source

Make Argon2 WebAssembly module unload after use (#5072)

pull/5729/head
Bernd Schoolmann 2 years ago committed by GitHub
parent
commit
f5c329030d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      libs/common/src/platform/services/web-crypto-function.service.ts
  2. 24
      patches/argon2-browser+1.18.0.patch

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

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

24
patches/argon2-browser+1.18.0.patch

@ -1,5 +1,5 @@ @@ -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 @@ -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 @@ -54,10 +60,8 @@ index ffa77a5..b498e2d 100644
+ }
+ } catch {
+ return false;
+ }
}
+ return false;
+ }
+
}
return {
ArgonType,
hash: argon2Hash,

Loading…
Cancel
Save