简体   繁体   English

提交没有明文密码的 Javascript 表格

[英]Submitting a Javascript form without plaintext password

I have a username and password stored in a db with 2 way encryption.我有一个用户名和密码存储在具有 2 路加密的数据库中。 I would like to use these to log into a site with a JS form like this:我想用这些来登录一个带有 JS 表单的网站,如下所示:

        var form = document.createElement("form");
        form.setAttribute("method", "post");
        form.setAttribute("action", "http://www.someloginscript.com/");
        var f = document.createElement("input");
        f.setAttribute("type", "text");
        f.setAttribute("name", "username");
        f.setAttribute("value", myUser);
        var f1 = document.createElement("input");
        f1.setAttribute("type", "text");
        f1.setAttribute("name", "password");
        f1.setAttribute("value", myPass);
        form.appendChild(field);
        form.appendChild(f1);
        document.body.appendChild(form);
        form.submit();

I would like to submit the form with the password, however to do this I need to decrypt it first.我想提交带有密码的表单,但是要做到这一点,我需要先解密它。 If I decrypt it then the password is visible through the 'Inspect Element' functions.如果我解密它,那么密码是通过“检查元素”功能可见的。 I obviously don't want this.我显然不想要这个。

I have stumbled upon a site called www.clipperz.com which does exactly what I want but I am not sure how.我偶然发现了一个名为 www.clipperz.com 的网站,它完全符合我的要求,但我不确定如何。 Do I need to implement their open source encryption library from http://sourceforge.net/projects/clipperz/ ?我是否需要从http://sourceforge.net/projects/clipperz/实现他们的开源加密库? Or is it all smoke and mirrors that makes it appear more secure?或者是所有的烟雾和镜子使它看起来更安全?

thanks!谢谢!

edit: I now know that there is no secure way of doing this.编辑:我现在知道没有安全的方法可以做到这一点。 Is using curl a more secure way of submitting this form?使用 curl 提交此表单是否更安全? This way I can keep all the handling of passwords server side?这样我可以保留服务器端对密码的所有处理吗?

You haven't specified it exactly, but it sounds like you're trying to use Javascript on one site to automate a login process into another site?您尚未准确指定它,但听起来您正试图在一个站点上使用 Javascript 来自动化登录到另一个站点的过程? Is that correct?那是对的吗? It also sounds like you want to use a general login for all users, which you need to prevent the users from seeing.听起来您还想为所有用户使用通用登录名,您需要防止用户看到。

I don't think this will be workable in the way you're trying to do it.我认为这不会以您尝试的方式可行。 The problem is that the user on the browser has complete access to the Javascript code and all the data it uses, via tools like Firebug.问题是浏览器上的用户可以通过 Firebug 等工具完全访问 Javascript 代码及其使用的所有数据。 Using these tools, he can even go as far as modifying the code after the page has loaded.使用这些工具,他甚至可以在页面加载后修改代码。

In short, there is no way of letting Javascript handle the data without giving the user the ability to see it.简而言之,没有办法让 Javascript 处理数据而不让用户能够看到它。

I would suggest a better approach might be something as follows:我建议更好的方法可能如下:

  • Site 1 sends a message to Site 2, informing it that it wants to log in a user.站点 1 向站点 2 发送消息,通知它要登录用户。 It tells it the users IP address, the login details it wants to use and other relevant details.它告诉它用户 IP 地址、它要使用的登录详细信息和其他相关详细信息。

  • Site 2 responds to Site 1 with a token code which Site 1 then sends to the user's browser.站点 2 使用令牌代码响应站点 1,然后站点 1 将其发送到用户的浏览器。

  • The Javascript code on the user's browser then posts the token to Site 2 instead of a login name and password.用户浏览器上的 Javascript 代码然后将令牌发布到站点 2,而不是登录名和密码。

  • Site 2 recognises it as the token it just gave to Site 1, and that it has come from the IP address it was told about, and logs the user in as if it had received a normal set of login details.站点 2 将其识别为它刚刚提供给站点 1 的令牌,并且它来自被告知的 IP 地址,并像收到一组正常的登录详细信息一样登录用户。

This process obviously requires you to write code on both Site 1 and Site 2, so you have to have full access to both of them.这个过程显然需要您在站点 1 和站点 2 上编写代码,因此您必须拥有对它们的完全访问权限。 If Site 2 is a third party system, then you may have to come up with something else.如果站点 2 是第三方系统,那么您可能需要想出一些别的东西。

Whatever information you end up sending to the third-party site, will have to be made available to the user's browser at some point - and at that point they'll be able to inspect it and get the information out.无论您最终发送到第三方站点的任何信息,都必须在某个时间点提供给用户的浏览器 - 届时他们将能够检查它并获取信息。

Alternatively, they could look at the HTTP requests being made from their machine.或者,他们可以查看从他们的机器发出的 HTTP 请求。

The point is, information on the user's machine can't be hidden from the user if it needs to be in a decrypted state on their machine at any point.关键是,如果用户机器上的信息需要随时在他们机器上的解密 state 中,则不能对用户隐藏。

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

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