Skip to content

Commit e4fee14

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

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

cake/libs/debugger.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,16 @@ function exportVar($var, $recursion = 0) {
499499
case 'object':
500500
return get_class($var) . "\n" . $_this->__object($var);
501501
case 'array':
502+
$var = array_merge($var, array_intersect_key(array(
503+
'password' => '*****',
504+
'login' => '*****',
505+
'host' => '*****',
506+
'database' => '*****',
507+
'port' => '*****',
508+
'prefix' => '*****',
509+
'schema' => '*****'
510+
), $var));
511+
502512
$out = "array(";
503513
$vars = array();
504514
foreach ($var as $key => $val) {

cake/tests/cases/libs/debugger.test.php

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

0 commit comments

Comments
 (0)