mostro-web
mostro-web copied to clipboard
Enhance Local Password and Key Management Security
The current implementation of password and private key handling stores decrypted private keys in localStorage, which poses a significant security risk:
nuxtClientInit() {
const decryptedPrivKey = ref<string | null>(localStorage.getItem(AUTH_LOCAL_STORAGE_DECRYPTED_KEY));
if (decryptedPrivKey.value) {
try {
this.privKey = decryptedPrivKey.value;
this.pubKey = getPublicKey(Buffer.from(this.privKey, 'hex'));
this.authMethod = AuthMethod.LOCAL;
} catch (err) {
console.warn('Error setting local key from local storage: ', err);
this.delete();
}
}
watch(() => this.privKey, (newVal) => {
localStorage.setItem(AUTH_LOCAL_STORAGE_DECRYPTED_KEY, newVal || '');
});
},
Here are suggested fixes:
-
Avoid storing decrypted private keys:
- Keep decrypted keys in memory and never persist them to
localStorage. - Use Vue's reactive state or composables to handle keys temporarily.
- Keep decrypted keys in memory and never persist them to
-
Use Web Crypto API for Encryption:
- Encrypt sensitive data before storing it.
- Derive keys securely using a passphrase with PBKDF2 or Argon2.
-
Implement a TTL (Time-to-Live):
- Add an expiration mechanism for encrypted keys stored in
localStorage.
- Add an expiration mechanism for encrypted keys stored in