Skip to content

Commit

Permalink
Adding an array cast to fix issues where users could modify cookie
Browse files Browse the repository at this point in the history
values causing iteration errors.  Fixes #1309
  • Loading branch information
markstory committed Nov 25, 2010
1 parent 390a7ae commit 1dfe2ac
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 2 additions & 2 deletions cake/libs/controller/components/cookie.php
Expand Up @@ -405,7 +405,7 @@ function __decrypt($values) {
$decrypted = array();
$type = $this->__type;

foreach ($values as $name => $value) {
foreach ((array)$values as $name => $value) {
if (is_array($value)) {
foreach ($value as $key => $val) {
$pos = strpos($val, 'Q2FrZQ==.');
Expand Down Expand Up @@ -481,4 +481,4 @@ function __explode($string) {
return $array;
}
}
?>
?>
13 changes: 12 additions & 1 deletion cake/tests/cases/libs/controller/components/cookie.test.php
Expand Up @@ -407,6 +407,17 @@ function testReadingCookieDataWithoutStartup() {
$this->Controller->Cookie->destroy();
unset($_COOKIE['CakeTestCookie']);
}
/**
* test that no error is issued for non array data.
*
* @return void
*/
function testNoErrorOnNonArrayData() {
$this->Controller->Cookie->destroy();
$_COOKIE['CakeTestCookie'] = 'kaboom';

$this->assertNull($this->Controller->Cookie->read('value'));
}
/**
* encrypt method
*
Expand Down Expand Up @@ -435,4 +446,4 @@ function __implode($array) {
return substr($string, 1);
}
}
?>
?>

0 comments on commit 1dfe2ac

Please sign in to comment.