代码之家  ›  专栏  ›  技术社区  ›  user1111929

为firefox密码自动完成伪造域?

  •  3
  • user1111929  · 技术社区  · 10 年前

    当运行两个不同的网站时 free.webhost.com/app1 free.webhost.com/app2 ,Firefox似乎很难为两者存储不同的登录凭据,特别是当相同的用户名与不同的密码一起使用时。如果用户在 /app1 站点是 Name pass1 而在另一个站点上 名称 pass2 ,则Firefox只能存储其中一个,并且在它们之间切换时会要求更改密码。

    我调查了这个问题,令我惊讶的是,这似乎是萤火虫bug库中的WONTFIX: https://bugzilla.mozilla.org/show_bug.cgi?id=263387

    在设计我的应用程序时,有什么方法可以解决这个问题吗?比如在PHP或html中设置某个cookie属性,甚至指定一个(假的)不同的域名,这样firefox就不再考虑 免费.webhost.com/app1 免费.webhost.com/app2 作为密码存储的同一个网站(因此可以为两个网站使用相同的用户名存储不同的密码)?

    4 回复  |  直到 10 年前
        1
  •  8
  •   user3942918    10 年前

    不,没有解决方法或技巧。将应用程序部署到不同的域-甚至不同的子域(例如。 app1.example.com app2.example.com )可以。

        2
  •  1
  •   Peter O. Manuel Pinto    10 年前

    我们需要一个 custom saver 我会尽量简明扼要。

    这非常有用 如果不需要浏览器保护程序 。我认为它可以有一些应用。


    基本的

    我建议在PHP中使用 不同的cookie 以保存会话 session_name session.name directive 。对于每个站点,我们必须设置会话名称。

    在HTML中,我们应该使用 不同的输入 name ,因此app1输入将为 <input type='email' name='email_app1' /> 和app2 email_app2 。我们还可以禁用 autocomplete .

    数据保存在本地 加密的 具有 AES 。为此,我们可以 CryptoJS . 我们也希望 salt hash 在客户端中。

    概念(概述) :

    • 本地保存 password 加密。已返回 通过登录 控制器 。当然,如果用户愿意。
    • 保存 salt 其在每次登录时都会发生变化。当然,如果用户愿意。
    • 当用户返回到登录页面时, JavaScript 检查是否存在 是一个 和它 将其发送到服务器 。PHP返回 口令 JavaScript 解密本地密码。

    示例代码 :

    在控制器中:

    // I use functions in the controller like example
    public function getLoginPage(){
       // it prints the html and js to login using the basics how i have said
    }
    
    // salt is sended by the JavaScript
    public function getPassphrase( $salt, $username ){
       $passPhrase = get_passphrase_from_salt( $salt, $username, Request::IP() );
       return $passPhrase;
    }
    
    // It is to get the salt
    public function getSalt( $username, $password ){
          $user = get_user( $username, $password );
    
          // if valid user...
          $passphrase = random_string();
          $salt = random_string();
    
          $encrypted = encrypt( $password, md5($passphrase) );
    
          save_in_table_salt( $salt, $passphrase, $username, Request::IP() );
    
          // it prints a JSON like example
          return json_encode( array( 'salt' => $salt, 'encrypted' => $encrypted) );
    }
    
    // ... Normal login etc you could change the salt and reset in the client
    

    在我们看来 JavaScript逻辑 。我用过 localstorage 但我认为这并不重要。

    // in login page
    window.onload = function(){
        if( localStorage.getItem('salt') !== null ) { // the data is saved
           // Get the passphrase
           ajax_call('post', 'getPassphrase', { 
                 salt: localStorage.getItem('salt'),
                 username: localStorage.getItem('username')
              }, function( passphrase ){
              // It sets the inputs values!
              document.getElementById('username_app1').value = localStorage.getItem('username');
              document.getElementById('password_app1').value = decrypt( localStorage.getItem('password'), CryptoJS.MD5(passphrase) );
           });
        }
    };
    
    // it captures the submit action
    document.getElementById('login_form').onsubmit = function(){
        // it asks to user if he wants save locally the credentials
        if( localStorage.getItem('salt') === null
            && confirm('Do you want save credentials?') ){
            var form = this;
            // get salt
            ajax_call('post', 'getSalt', {
                  user: document.getElementById('username_app1').value,
                  password: document.getElementById('password_app1').value
               }, function( object ){
               localStorage.setItem('salt', object.salt);
               localStorage.setItem('password', object.encrypted);
               localStorage.setItem('username', document.getElementById('username_app1').value );
    
               form.submit(); // now yes
            });
            return false; // it prevents submit
        }
    };
    

    您必须知道代码是一个示例。某些函数不存在 这只是为了被理解 我们需要更多的条件和逻辑来实现这一目标。

    已更新 :现在可以使用多台计算机和IP安全等!

        3
  •  1
  •   mikikg    10 年前

    由于Firefox中的内部凭据存储是按域组织的,而不是按URL组织的,因此没有解决方法。 即使更改输入HTML控件或表单标记的名称或ID也不会影响这一点。

    唯一的解决方案是将应用程序托管在不同的(子)域上。

        4
  •  1
  •   Tapaswi Panda    10 年前

    这里最好的解决方案可能是为应用程序创建两个不同的虚拟主机。 比如webhost.com和免费.webhost.com。

    How To Set Up Apache Virtual Hosts on Ubuntu 12.04 LTS

    希望这有帮助!!

    如果您在服务器中设置虚拟主机时遇到问题,请告诉我。

    注意:您需要创建DNS条目以访问您创建的新主机,或者需要将记录添加到您浏览站点的系统的主机文件中。