简体   繁体   English

将敏感数据存储在本地存储或会话存储中是否安全? Localstorage 允许对敏感数据进行任何攻击

[英]Is it safe to store a sensitive data in Local Stoarge or session storage? Localstorage allows to any attacks for sensitive data

In web application , How secure is local storage in Html5 or else is there any other way to secure the sensitive data in local storage.在 Web 应用程序中,Html5 中的本地存储有多安全,或者有没有其他方法可以保护本地存储中的敏感数据。

Project Structure:项目结构:

Front End: Html5,Angular js, Middletier: Asp.net webApi , BackEnd :Sql Server.前端:Html5,Angular js,中间层: Asp.net webApi,后端:Sql Server。

Once user login into the page, that credentials is encrypted by using some cryptography algorithms.It will be stored in db.用户登录页面后,该凭据将使用一些加密算法进行加密。它将存储在 db 中。

After that every child action like products list, order details, book history ,add product need to validate that.之后,每个子操作(如产品列表、订单详细信息、书籍历史记录、添加产品)都需要验证。

While refresh after the page, data gets lossed so need to persist the data so i have choose localstorage.在页面刷新后,数据丢失,因此需要保留数据,因此我选择了本地存储。 stored the username and password encrypted using some js algorithms and in put in local storage.存储使用一些 js 算法加密的用户名和密码并放入本地存储。

I feel it as not safe , because of any one can steal the data from the browser tools.我觉得它不安全,因为任何人都可以从浏览器工具中窃取数据。

Is there any alternative approach in this scenario or else this approach is secure.在这种情况下是否有任何替代方法,否则这种方法是安全的。

can anyone help me to process.谁能帮我处理。

There is something that every Webapp Craftsman must know:每个 Webapp 工匠都必须知道的一些事情:

There is no repository beyond your firewall that can be fully secure.防火墙之外没有可以完全安全的存储库。 Why?为什么? Because the open door that you NEED to allow your application manipulate the data is accessible to everyone.因为每个人都可以访问允许应用程序操作数据的大门。

Imagine that you decide to encrypt the content of the local storage.假设您决定加密本地存储的内容。

This will prevent someone with access to the browser's local storage (eg the developer tool) to be able to read/write the data.这将阻止有权访问浏览器本地存储(例如开发人员工具)的人读取/写入数据。 But how your application will access the data?但是您的应用程序将如何访问数据? You have two options:您有两个选择:

  1. Send the encryption algorithm + passphrase within the client-side app .在客户端应用程序中发送加密算法 + 密码 This will expose all your data if someone manage to read the code of your app and access to memory of the browser (eg the developer tool)如果有人设法读取您的应用程序的代码并访问浏览器的内存(例如开发人员工具),这将公开您的所有数据
  2. Send every data from the client-side to the server to be decrypted there .将所有数据从客户端发送到要在那里解密的服务器 Well ... this is pointless.嗯……这毫无意义。 Is better to store the data in the server for that matter.最好将数据存储在服务器中。

You can try as much as you want, you will need an open door, and that open door can be use by anyone.您可以随心所欲地尝试,您将需要一扇敞开的门,而这扇敞开的门可供任何人使用。

But I've a question for you: Do you really need a fully secure repository in the client side?但是我有一个问题要问您:您真的需要在客户端有一个完全安全的存储库吗? This kind of repository weren't created for be fully secure, but they are secure enough!这种存储库不是为了完全安全而创建的,但它们已经足够安全了!

For example, the session cookie of your web app is stored by the browser right?例如,您的网络应用程序的会话 cookie 是由浏览器存储的,对吗? And if someone steal that cookie, it can impersonate the user and your application will never notice it, right?如果有人窃取了那个 cookie,它可以冒充用户,而您的应用程序永远不会注意到它,对吧? This is pretty scary when you think about it.当你想到它时,这是非常可怕的。

Nowadays nobody put to much thinking on this because browsers are secure enough to protect cookies from malicious access.现在没有人对此多加考虑,因为浏览器足够安全,可以保护 cookie 免受恶意访问。 And of course, they did the same to protect the local local/session storage, IndexedDB, WebSQL, etc.当然,他们也做了同样的事情来保护本地本地/会话存储、IndexedDB、WebSQL 等。

So, if your data is more precious than your user session, keep it in the server.因此,如果您的数据比您的用户会话更宝贵,请将其保存在服务器中。 If not, go ahead and put it in the browser.如果没有,请继续并将其放入浏览器中。

PRO TIP: Consider encryption when storing in a no secure repository to make it harder to get.专业提示:在不安全的存储库中存储时考虑加密,使其更难获得。 But remember that this comes at a price: you will not be able to use the query system of those repositories to search over encrypted data.但请记住,这是有代价的:您将无法使用这些存储库的查询系统来搜索加密数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM