Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Password as argument displayed in stack-trace

We log all the exception that occurs in our code, with the stack-trace associated.

The problem comes from this function:

public function Authenticate($user, $password)
    //Authenticate the user
}

When an exception is thrown by this function, the stack-trace contains the parameters used: the user password is displayed in plain text.

How can I deal with that? Should I rewrite Authenticate function to accept only encrypted password? Can I disallow this particular parameter to be displayed in stack trace?

Any idea is welcome.

EDIT

I use the getTraceAsString function to log the trace.

like image 637
Getz Avatar asked Oct 03 '14 07:10

Getz


2 Answers

You could use Exception::getTrace() method to collect information, and write your own custom getTraceAsString(), not including parameters.

See this example from the comments on Exception::getTrace() docs.

  function MakePrettyException(Exception $e) {
    $trace = $e->getTrace();

    $result = 'Exception: "';
    $result .= $e->getMessage();
    $result .= '" @ ';
    if($trace[0]['class'] != '') {
      $result .= $trace[0]['class'];
      $result .= '->';
    }
    $result .= $trace[0]['function'];
    $result .= '();<br />';

    return $result;
  }
like image 112
mehmetseckin Avatar answered Oct 17 '22 02:10

mehmetseckin


Two things I would suggest:

  1. The stack trace should not be visible on the client end (if not already)

  2. Authenticate should only accept a hashed version of the password

That way, even if someone has a copy of the hashed password, they can't use it to login, or use it to reverse the password.

The ideal method of course would be to use something like Xdebug, where the default setting of collect_params is 0, meaning variables are not shown on the stack trace.

like image 20
Dave Chen Avatar answered Oct 17 '22 03:10

Dave Chen