2015-09-16 20 views
0

我有xdebug設置用於錯誤跟蹤,我在登錄表單上看到問題。只要用戶嘗試登錄,xdebug就會以usernamepassword引發堆棧跟蹤。現在問題是如何用佔位符字符替換那些例如*,以避免登錄用戶名/密碼。使用xdebug時避免泄漏用戶名/密碼

這是不是一個PRODUCTION SERVER

回答

1

這有點晚,但我一直在尋找這個問題的答案,並沒有發現任何。這是我想出的。

使用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

+0

您想添加一些描述爲什麼這應該工作或背後的哲學是什麼,謝謝。 – sakhunzai

+1

我在答案中增加了更多細節。 –

1

嗯,你真的打開錯誤報告上的生產?這樣一個勇敢的人:)

禁用它!生產應該記錄錯誤,永遠不要顯示它們。

+0

獎勵:如果你關心的人閱讀的日誌,你可以使用['\鈉\ crypto_box_seal()'](https://paragonie.com/book/pecl-libsodium /read/08-advanced.md#crypto-box-seal)與一個crypto_box公共密鑰,密鑰保存在一個airgapped計算機中。這可以讓你混淆它們而不會丟失數據。 –

+0

@Elon我沒有說它的生產。 – sakhunzai

+0

如果不是生產,那麼就沒有機會泄漏任何東西,對吧? –