Skip to content

Commit

Permalink
[mms] Only store keys in cookie if cookies are in use (Bug #13284; th…
Browse files Browse the repository at this point in the history
…omas.jarosch@intra2net.com).
  • Loading branch information
slusarz committed Jun 24, 2014
1 parent 9f02bf8 commit 6c50180
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
24 changes: 13 additions & 11 deletions framework/Secret/lib/Horde/Secret.php
Expand Up @@ -124,7 +124,7 @@ protected function _getCipherOb($key)

/**
* Generate a secret key (for encryption), either using a random
* md5 string and storing it in a cookie if the user has cookies
* string and storing it in a cookie if the user has cookies
* enabled, or munging some known values if they don't.
*
* @param string $keyname The name of the key to set.
Expand All @@ -133,23 +133,17 @@ protected function _getCipherOb($key)
*/
public function setKey($keyname = self::DEFAULT_KEY)
{
$set = true;

if (isset($_COOKIE[$this->_params['session_name']])) {
if (isset($_COOKIE[$keyname . '_key'])) {
$key = $_COOKIE[$keyname . '_key'];
$set = false;
} else {
$key = $_COOKIE[$keyname . '_key'] = strval(new Horde_Support_Randomid());
$this->_setCookie($keyname, $key);
}
} else {
$key = session_id();
}

if ($set) {
$this->_setCookie($keyname, $key);
}

return $key;
}

Expand Down Expand Up @@ -187,9 +181,13 @@ public function getKey($keyname = self::DEFAULT_KEY)
*/
public function clearKey($keyname = self::DEFAULT_KEY)
{
if (isset($_COOKIE[$this->_params['session_name']]) &&
isset($_COOKIE[$keyname . '_key'])) {
$this->_setCookie($keyname, false);
if (isset($_COOKIE[$this->_params['session_name']])) {
if (isset($_COOKIE[$keyname . '_key'])) {
$this->_setCookie($keyname, false);
return true;
}
} elseif (isset($this->_keyCache[$keyname])) {
unset($this->_keyCache[$keyname]);
return true;
}

Expand All @@ -204,6 +202,10 @@ public function clearKey($keyname = self::DEFAULT_KEY)
*/
protected function _setCookie($keyname, $key)
{
if (!isset($_COOKIE[$this->_params['session_name']])) {
return;
}

@setcookie(
$keyname . '_key',
$key,
Expand Down
2 changes: 2 additions & 0 deletions framework/Secret/package.xml
Expand Up @@ -28,6 +28,7 @@
</stability>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
* [mms] Only store keys in cookie if cookies are in use (Bug #13284; thomas.jarosch@intra2net.com).
* [mms] Correctly clear secret key from cookie data (Bug #13283; thomas.jarosch@intra2net.com).
</notes>
<contents>
Expand Down Expand Up @@ -394,6 +395,7 @@ Initial release as a PEAR package
<date>2012-11-19</date>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
* [mms] Only store keys in cookie if cookies are in use (Bug #13284; thomas.jarosch@intra2net.com).
* [mms] Correctly clear secret key from cookie data (Bug #13283; thomas.jarosch@intra2net.com).
</notes>
</release>
Expand Down

0 comments on commit 6c50180

Please sign in to comment.