JavaScript、node.js 和安全性
我的网站上有一个用户注册表单,它只是使用 socket.io 以纯文本形式将数据(用户名、密码和电子邮件)发送到服务器。我知道这是一个非常糟糕的解决方案,那么我用什么来隐藏信息呢?您能否解释一下人们如何获得这些信息,以便我知道要避免什么?我听说过 jsAES,它可以加密这些内容,但是客户端和服务器如何知道钥匙?
I have an user registration form on my website, and it just sends the data (username, password and email) to the server in plain text using socket.io. I know that this is a really bad solution, so what do I use to hide the information? And can you explain how could someone get the information so I know what to avoid? I heard about jsAES, that encrypts the stuff, but how will both the client and the server know the key?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以做的是在 JavaScript 中使用非对称加密:包含 JavaScript 加密代码(例如, RSA,不是对称 AES)和代码中的公钥。提交后,加密所有输入并将其发送到服务器,并在服务器上使用私钥进行解密。然而,熟练的攻击者可以简单地更改 JavaScript 或注入自己的 JavaScript 来规避这种客户端加密。此外,它还需要 JavaScript,有安全意识的访问者可能会禁用 JavaScript。
使用 HTTPS,而不是推出您自己的解决方案。生成密钥对,获取其证书,然后配置您的服务器以服务 HTTPS 请求。使用 HTTP 严格传输安全 强制所有连接使用 HTTPS。
What you can do is use asymmetric cryptography in JavaScript: Include JavaScript encryption code (for example, RSA, not the symmetric AES) and a public key in your code. Upon submit, encrypt all inputs and send them to the server where they are decrypted with the private key. However, a skilled attacker can simply change that JavaScript or inject his own to circumvent this client-side encryption. Also, it requires JavaScript, which may disabled by security-conscious visitors.
Instead of rolling out your own solution, use HTTPS. Generate a key pair, get a certificate for it, and configure your server to serve HTTPS requests. Use HTTP Strict Transport Security to force HTTPS for all connections.