使用 xdebug 时避免泄漏 username/password

Avoiding Leaking of username/password when using xdebug

我已经 xdebug 设置了错误跟踪,但我在登录表单上看到了一个问题。一旦用户尝试登录 xdebug 就会抛出带有 username password 的堆栈跟踪。现在的问题是如何用占位符字符替换那些字符,例如 * ,以避免记录 username/passwords.

这不是 PRODUCTION SERVER

嗯,你真的打开了生产错误报告吗?好勇敢的人:)

禁用它!生产应该记录错误,永远不要显示它们。

这有点晚了,但我一直在寻找这个问题的答案,但没有找到任何答案。这是我的想法。

使用 setter(或构造函数)将凭据传递给您的身份验证模型,而不是将它们直接传递给任何可能有错误的函数:

class Auth
{
    protected
        $username=null,
        $password=null;
    ...
    public function setCredentials($username,$password)
    {
        $this->username=$username;
        $this->password=$password;
    }
    public function login()
    {
        $result=false;
        //credentials are not passed to this function
        //so if something goes wrong they won't end up
        //in the stack trace
        ...retrieve user record from database...
        $result=password_verify($this->password,$data['password_hash']));
        if($result)
        {
            ...success - finish logging user in...
        }
        return $result;
    }
    ...
}

setCredentials函数很简单,里面没有什么会引发异常的地方。

登录函数不将凭据作为参数,因此如果出现问题,您的密码将不会出现在堆栈跟踪中(而不是 Auth::login('thisisme','thisismypassword') 在堆栈跟踪中,您将看到 Auth::login())

据我所知,password_verify 函数不会抛出异常,但如果您偏执,可以将其包装在 try/catch 块中:

try
{
    $result=password_verify($this->password,$data['password_hash']));
}
catch(Exception $ex)
{
    error_log(get_class($this).'::'.__FUNCTION__.': password_verify() failed.');
}

应该使用 password_hash()

设置密码哈希

http://php.net/manual/en/function.password-hash.php

http://php.net/manual/en/function.password-verify.php