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

How secure is it really?

Open GsHeri opened this issue 5 years ago • 17 comments

Heya, i'm sorry if this is a stupid question, i'm no security expert. but if everything has to be two-way, then the secret has to be accessible for every attacker... right? so is it really just obfuscating the data, or is there a real encryption at work here, which is hard (or virtually impossible?) to break?

would someone explain it to me? thanks :)

GsHeri avatar Jan 24 '20 17:01 GsHeri

I was thinking the same...how is it?

ux-engineer avatar Mar 08 '20 11:03 ux-engineer

From what I understand, the key used to perform the encryption is encrypted with a metaKey (see src/utils.js its value is _secure__ls__metadata) and then stored in the local storage.

It seems we can't override the value of this key, so IMHO it is not secure at all.

linkdd avatar Apr 29 '20 15:04 linkdd

It's not secure at all. The keys are right there, in the localstorage.

Please, don't use this project for anything. It is dangerous.

I tried to raise an issue because this project is irresponsible with their use of "secure" in marketing it, but they deleted the issue without even commenting.

karelbilek avatar Sep 28 '21 15:09 karelbilek

I dont agree with you.

var ls1 = new SecureLS({encodingType: 'des', encryptionSecret: 'my-secret-key-1'});

Try before commenting.

qxygene avatar Jan 01 '22 01:01 qxygene

Do we have a consensus on this matter?

Is this really secure?

I'd like to see some demo POC

vicenterusso avatar Jan 12 '22 13:01 vicenterusso

Try to read this data;

U2FsdGVkX1+90T12L1muE9LFKA9Q3oAaIq6KOLvv1A33JZ8udhFsURiCqVS0JaqrIQ5AWVis+JlN/TWWz3okf0Hl1Id3X728jzMlMKKvJWjlF/wjEWKQlGsV791FMLomS09Yoi2sko8ohF+VPpy+LglqxRIUqTvOua8iLJLngcTRMIib1gY4UZ0sGrcJqNiyoQNWxW5j5pn5nze5EpTwbZgwnvK4vOxzpv00CqfxtILsJfEM4oGSJ6zGb5Vk5iuPlRoOMYqMWp9lcicgN98xb4jNnTsgKWf/G71p4SlCFePlrkra4svgujbNKMstOA06Hi6fvipyHps2rPJQ763jdbYTuy3f5Yv1U7ri0RS5DNOKPOqr0p8xmg8PCDJa70XgWIUKLeW6aDZpSg73YonmRw0MX6cKPtAZ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ure.

qxygene avatar Jan 12 '22 18:01 qxygene

The issue I brought up is not with the encrypted values for the data you are storing (which I believe is what you posted), but the _secure__ls__metadata key that's also stored in localStorage along with that value. You can easily decode that (it's not encrypted, just compressed)

@bozzaj So, just to be clear, changing the meta key name is the only thing we can do, right? I mean, just to make it hard to someone guess the name (only because it's a public and popular library).

What I mean is, we are not 100% secure if somehow the attacker knows the meta key name. Right?

vicenterusso avatar Jan 13 '22 00:01 vicenterusso

Changing the meta key name would obfuscate the fact that you're using the library and then it just becomes data sitting in localStorage.

Ignoring the fact that it's fairly simple to fetch all keys from localStorage then try to decode it using the algo you mentioned earlier, to see if there is a key that can be decoded. If there is, you got your metadata without knowing the key name beforehand.

Let's get some fact straight:

STORING SENSITIVE DATA IN LOCALSTORAGE IS NEVER SECURE AND NEVER WILL BE.

linkdd avatar Jan 13 '22 01:01 linkdd

https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/HTML5_Security_Cheat_Sheet.md#local-storage

Also known as Offline Storage, Web Storage. Underlying storage mechanism may vary from one user agent to the next. In other words, any authentication your application requires can be bypassed by a user with local privileges to the machine on which the data is stored. Therefore, it's recommended to avoid storing any sensitive information in local storage where authentication would be assumed.

linkdd avatar Jan 13 '22 01:01 linkdd

moved on to something that provided (for me) significantly better security, even with localStorage.

Please do share your findings :)

vicenterusso avatar Jan 13 '22 01:01 vicenterusso

@bozzaj _secure__ls__metadata key will not be stored in localStorage as "_secure__ls__metadata " unless you change key:TO_SOMETING, You can never decode that because it is encrypted which i posted above.

https://www.devglan.com/online-tools/triple-des-encrypt-decrypt No chance!

The metadata is not always only base64,, you can choose methods as i choose DES. Here is config;

const ls = new SecureLS({ encodingType: 'des', isCompression: false, encryptionSecret: '_my_key', });

For example i use vue, vuex, vuex-persistedstate. With secure-ls everything is secured. Why this is so difficult for you to understand?

qxygene avatar Jan 14 '22 00:01 qxygene

if the _secure__ls__metadata key is saved in a secure cookie it may be more secure?

XzaR90 avatar Jan 14 '22 13:01 XzaR90

I forked this and created another version, https://github.com/xzar90/secure-storage but it has less features but the metadata key is stored in a cookie instead and the code is enclosed.

XzaR90 avatar Jan 26 '22 16:01 XzaR90

You need to figure out what the "secure" is actually secure against/from.

Secure against user tampering? That's basically impossible client-side; if javascript can read it client-side, user can read it client-side.

You can heavily obfuscate it, which is "secure" I guess, but then the javascript itself would need to be obfuscated too. But in the end it's kind of "DRM".

Secure against other websites reading it? Browsers already do this. You cannot have different origins read same localstorage...

So you must define what is the threat model you are protecting against, really.

karelbilek avatar Jan 28 '22 03:01 karelbilek

Este paquete utiliza crypto-js: https://github.com/advisories/GHSA-xwcq-pm8m-c4vf

jonyedu avatar Oct 28 '23 21:10 jonyedu