Skip to content

Commit 5813af1

Browse files
committed
lib: clear in-memory credentials after connection
1 parent af1604c commit 5813af1

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

lib/lnc.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,12 @@ export default class LNC {
229229
clearInterval(interval);
230230
resolve();
231231
log.info('The WASM client is connected to the server');
232+
233+
// clear the in-memory credentials after connecting if the
234+
// credentials are persisted in local storage
235+
if (this.credentials.password) {
236+
this.credentials.clear(true);
237+
}
232238
} else if (counter > 20) {
233239
clearInterval(interval);
234240
reject(

lib/types/lnc.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ export interface CredentialStore {
132132
* credentials persisted in the store
133133
*/
134134
isPaired: boolean;
135-
/** Clears any persisted data in the store */
136-
clear(): void;
135+
/**
136+
* Clears the in-memory and persisted data in the store.
137+
* @param memoryOnly If `true`, only the in-memory data will be cleared. If
138+
* `false` or `undefined`, the persisted data will be cleared as well.
139+
* The default is `undefined`.
140+
*/
141+
clear(memoryOnly?: boolean): void;
137142
}

lib/util/credentialStore.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ export default class LncCredentialStore implements CredentialStore {
105105
if (this.remoteKey)
106106
this.persisted.remoteKey = this._encrypt(this.remoteKey);
107107
this._save();
108+
109+
// once the encrypted data is persisted, we can clear the plain text
110+
// credentials from memory
111+
this.clear(true);
108112
}
109113
}
110114

@@ -170,9 +174,11 @@ export default class LncCredentialStore implements CredentialStore {
170174
}
171175

172176
/** Clears any persisted data in the store */
173-
clear() {
174-
const key = `${STORAGE_KEY}:${this.namespace}`;
175-
localStorage.removeItem(key);
177+
clear(memoryOnly?: boolean) {
178+
if (!memoryOnly) {
179+
const key = `${STORAGE_KEY}:${this.namespace}`;
180+
localStorage.removeItem(key);
181+
}
176182
this.persisted = {
177183
salt: '',
178184
cipher: '',

0 commit comments

Comments
 (0)