在客户端存储敏感信息(Web)
Store sensitive information on the client side (Web)
我开发了一个网站,需要在客户端存储一个私钥。
如何在客户端安全地存储这个变量?
我可以使用 sessionStorage 吗?
(我希望只有当前用户可以访问此(可变)信息。一旦他关闭浏览器,就必须删除数据。)
谢谢。
在顶层,是的,sessionStorage
将满足您的需求。引用 MDN’s page on sessionStorage
:
- A page session lasts as long as the browser is open, and survives over page reloads and restores.
- Opening a page in a new tab or window creates a new session with the value of the top-level browsing context, which differs from how session cookies work.
- Opening multiple tabs/windows with the same URL creates sessionStorage for each tab/window.
- Closing a tab/window ends the session and clears objects in sessionStorage.
虽然有几件事需要注意。首先,与服务器的任何连接都需要安全地完成。这需要一个 HTTPS 连接,此时可能使用 TLS 1.2 或 1.3。
其次,您需要确保页面环境干净。这意味着您无法加载可能泄露私钥的第 3 方 JavaScript。至少,您加载的任何第三方 JS 都需要先进行审核,然后添加 integrity
attribute 以确保它不会更改。
最后,您可能希望添加一些内容以在用户使用完页面后销毁密钥。这可能是警告他们在使用完系统后关闭页面,或者更自动的事情,比如在 x 分钟后退出密钥并让系统及时协商一个新密钥.显然,安全性和可用性之间存在平衡,但最好的系统可以以用户透明的方式做到这一点。
我开发了一个网站,需要在客户端存储一个私钥。 如何在客户端安全地存储这个变量? 我可以使用 sessionStorage 吗?
(我希望只有当前用户可以访问此(可变)信息。一旦他关闭浏览器,就必须删除数据。)
谢谢。
在顶层,是的,sessionStorage
将满足您的需求。引用 MDN’s page on sessionStorage
:
- A page session lasts as long as the browser is open, and survives over page reloads and restores.
- Opening a page in a new tab or window creates a new session with the value of the top-level browsing context, which differs from how session cookies work.
- Opening multiple tabs/windows with the same URL creates sessionStorage for each tab/window.
- Closing a tab/window ends the session and clears objects in sessionStorage.
虽然有几件事需要注意。首先,与服务器的任何连接都需要安全地完成。这需要一个 HTTPS 连接,此时可能使用 TLS 1.2 或 1.3。
其次,您需要确保页面环境干净。这意味着您无法加载可能泄露私钥的第 3 方 JavaScript。至少,您加载的任何第三方 JS 都需要先进行审核,然后添加 integrity
attribute 以确保它不会更改。
最后,您可能希望添加一些内容以在用户使用完页面后销毁密钥。这可能是警告他们在使用完系统后关闭页面,或者更自动的事情,比如在 x 分钟后退出密钥并让系统及时协商一个新密钥.显然,安全性和可用性之间存在平衡,但最好的系统可以以用户透明的方式做到这一点。