secure-ls
secure-ls copied to clipboard
removeAll() removes the wrong metaKey
When using encryptionNamespace, removeAll() removes the default metaKey (from utils.metaKey) instead of the namespace metaKey from getMetaKey()
Using removeAll
deletes all the keys created by secure-ls lib. Please refer the docs.
Please let me know if it causes any issue.
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?
I think there's some issue for sure. WIll debug and let you know. Thanks for reporting this.