secure-ls icon indicating copy to clipboard operation
secure-ls copied to clipboard

removeAll() removes the wrong metaKey

Open bozzaj opened this issue 4 years ago • 3 comments

When using encryptionNamespace, removeAll() removes the default metaKey (from utils.metaKey) instead of the namespace metaKey from getMetaKey()

bozzaj avatar Jun 30 '20 19:06 bozzaj

Using removeAll deletes all the keys created by secure-ls lib. Please refer the docs.

Please let me know if it causes any issue.

softvar avatar Jul 05 '20 14:07 softvar

I understand that. However, take this example:

// Use a private namespace with a metaKey of _secure__ls__metadata__private
const ls1 = new SecureLS({ encryptionNamespace: "private", encryptionSecret: "secret1" });
ls1.set("key1", "key1_value");

// Use a default namespace with a metaKey of _secure__ls__metadata
const ls2 = new SecureLS({ encryptionSecret: "secret2" });
ls2.set("key2", "key2_value");

// Remove first SecureLS instance
ls1.removeAll();

The ls1.removeAll() call removes all the keys (key1) for ls1 but doesn't remove _secure__ls__metadata__private. However, it DOES remove the metaKey secure__ls__metadata which is used by the default namespace ls2 object. This leaves localStorage with key2 and _secure__ls__metadata__private.

JSFiddle: https://jsfiddle.net/r4qodgm5/

Perhaps I don't understand the reason for namespaces? Why would removeAll() on the private namespace remove the metaData for the default namespace but leave the metaData for the private namespace?

bozzaj avatar Jul 05 '20 16:07 bozzaj

I think there's some issue for sure. WIll debug and let you know. Thanks for reporting this.

softvar avatar Jul 05 '20 20:07 softvar