Skip to content

Commit fcd0505

Browse files
committed
Hide db credentials
To protect users who have publically accessible installs with debug turned on - *** out db login credentials
1 parent 08f1afe commit fcd0505

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

lib/Cake/Test/Case/Utility/DebuggerTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,4 +326,40 @@ public function testGetInstance() {
326326
$result = Debugger::getInstance('Debugger');
327327
$this->assertIsA($result, 'Debugger');
328328
}
329+
330+
/**
331+
* testNoDbCredentials
332+
*
333+
* If a connection error occurs, the config variable is passed through exportVar
334+
* *** our database login credentials such that they are never visible
335+
*
336+
* @access public
337+
* @return void
338+
*/
339+
function testNoDbCredentials() {
340+
$config = array(
341+
'driver' => 'mysql',
342+
'persistent' => false,
343+
'host' => 'void.cakephp.org',
344+
'login' => 'cakephp-user',
345+
'password' => 'cakephp-password',
346+
'database' => 'cakephp-database',
347+
'prefix' => ''
348+
);
349+
350+
$output = Debugger::exportVar($config);
351+
352+
$expectedArray = array(
353+
'driver' => 'mysql',
354+
'persistent' => false,
355+
'host' => '*****',
356+
'login' => '*****',
357+
'password' => '*****',
358+
'database' => '*****',
359+
'prefix' => ''
360+
);
361+
$expected = Debugger::exportVar($expectedArray);
362+
363+
$this->assertEqual($expected, $output);
364+
}
329365
}

lib/Cake/Utility/Debugger.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,16 @@ public static function exportVar($var, $recursion = 0) {
464464
case 'object':
465465
return get_class($var) . "\n" . self::_object($var);
466466
case 'array':
467+
$var = array_merge($var, array_intersect_key(array(
468+
'password' => '*****',
469+
'login' => '*****',
470+
'host' => '*****',
471+
'database' => '*****',
472+
'port' => '*****',
473+
'prefix' => '*****',
474+
'schema' => '*****'
475+
), $var));
476+
467477
$out = "array(";
468478
$vars = array();
469479
foreach ($var as $key => $val) {

0 commit comments

Comments
 (0)