Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:EllisLab/CodeIgniter into codeig…
Browse files Browse the repository at this point in the history
…niter/develop
  • Loading branch information
alexbilbie committed Oct 18, 2012
2 parents 1876327 + cf264e0 commit 447d803
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 50 deletions.
34 changes: 15 additions & 19 deletions system/libraries/Email.php
Expand Up @@ -292,16 +292,7 @@ public function to($to)
$this->set_header('To', implode(', ', $to));
}

switch ($this->_get_protocol())
{
case 'smtp':
$this->_recipients = $to;
break;
case 'sendmail':
case 'mail':
$this->_recipients = implode(', ', $to);
break;
}
$this->_recipients = $to;

return $this;
}
Expand Down Expand Up @@ -763,7 +754,7 @@ protected function _get_alt_message()
{
if ($this->alt_message !== '')
{
return $this->word_wrap($this->alt_message, '76');
return $this->word_wrap($this->alt_message, 76);
}

$body = preg_match('/\<body.*?\>(.*)\<\/body\>/si', $this->_body, $match) ? $match[1] : $this->_body;
Expand All @@ -786,12 +777,12 @@ protected function _get_alt_message()
* @param int
* @return string
*/
public function word_wrap($str, $charlim = '')
public function word_wrap($str, $charlim = NULL)
{
// Se the character limit
if ($charlim === '')
// Set the character limit, if not already present
if (empty($charlim))
{
$charlim = ($this->wrapchars === '') ? 76 : $this->wrapchars;
$charlim = empty($this->wrapchars) ? 76 : $this->wrapchars;
}

// Reduce multiple spaces
Expand Down Expand Up @@ -1105,6 +1096,10 @@ protected function _build_message()
*/
protected function _prep_quoted_printable($str)
{
// We are intentionally wrapping so mail servers will encode characters
// properly and MUAs will behave, so {unwrap} must go!
$str = str_replace(array('{unwrap}', '{/unwrap}'), '', $str);

// RFC 2045 specifies CRLF as "\r\n".
// However, many developers choose to override that and violate
// the RFC rules due to (apparently) a bug in MS Exchange,
Expand All @@ -1130,10 +1125,6 @@ protected function _prep_quoted_printable($str)
$str = str_replace(array("\r\n", "\r"), "\n", $str);
}

// We are intentionally wrapping so mail servers will encode characters
// properly and MUAs will behave, so {unwrap} must go!
$str = str_replace(array('{unwrap}', '{/unwrap}'), '', $str);

$escape = '=';
$output = '';

Expand Down Expand Up @@ -1408,6 +1399,11 @@ protected function _spool_email()
*/
protected function _send_with_mail()
{
if (is_array($this->_recipients))
{
$this->_recipients = implode(', ', $this->_recipients);
}

if ($this->_safe_mode === TRUE)
{
return mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str);
Expand Down
47 changes: 27 additions & 20 deletions system/libraries/Session/drivers/Session_cookie.php
Expand Up @@ -308,7 +308,7 @@ public function sess_destroy()
}

// Kill the cookie
$this->_setcookie($this->sess_cookie_name, addslashes(serialize(array())), ($this->now - 31500000),
$this->_setcookie($this->sess_cookie_name, '', ($this->now - 31500000),
$this->cookie_path, $this->cookie_domain, 0);

// Kill session data
Expand Down Expand Up @@ -372,27 +372,31 @@ protected function _sess_read()
return FALSE;
}

$len = strlen($session) - 40;

if ($len < 0)
{
log_message('debug', 'The session cookie was not signed.');
return FALSE;
}

// Check cookie authentication
$hmac = substr($session, $len);
$session = substr($session, 0, $len);

if ($hmac !== hash_hmac('sha1', $session, $this->encryption_key))
{
log_message('error', 'The session cookie data did not match what was expected.');
$this->sess_destroy();
return FALSE;
}

// Check for encryption
if ($this->sess_encrypt_cookie === TRUE)
{
// Decrypt the cookie data
$session = $this->CI->encrypt->decode($session);
}
else
{
// Encryption was not used, so we need to check the md5 hash in the last 32 chars
$len = strlen($session)-32;
$hash = substr($session, $len);
$session = substr($session, 0, $len);

// Does the md5 hash match? This is to prevent manipulation of session data in userspace
if ($hash !== md5($session.$this->encryption_key))
{
log_message('error', 'The session cookie data did not match what was expected. This could be a possible hacking attempt.');
$this->sess_destroy();
return FALSE;
}
}

// Unserialize the session array
$session = $this->_unserialize($session);
Expand Down Expand Up @@ -658,10 +662,13 @@ protected function _set_cookie()
// Serialize the userdata for the cookie
$cookie_data = $this->_serialize($cookie_data);

$cookie_data = ($this->sess_encrypt_cookie === TRUE)
? $this->CI->encrypt->encode($cookie_data)
// if encryption is not used, we provide an md5 hash to prevent userside tampering
: $cookie_data.md5($cookie_data.$this->encryption_key);
if ($this->sess_encrypt_cookie === TRUE)
{
$cookie_data = $this->CI->encrypt->encode($cookie_data);
}

// Require message authentication
$cookie_data .= hash_hmac('sha1', $cookie_data, $this->encryption_key);

$expire = ($this->sess_expire_on_close === TRUE) ? 0 : $this->sess_expiration + time();

Expand Down
20 changes: 15 additions & 5 deletions system/libraries/Session/drivers/Session_native.php
Expand Up @@ -55,7 +55,9 @@ protected function initialize()
'sess_time_to_update',
'cookie_prefix',
'cookie_path',
'cookie_domain'
'cookie_domain',
'cookie_secure',
'cookie_httponly'
);

foreach ($prefs as $key)
Expand All @@ -82,6 +84,9 @@ protected function initialize()
$expire = 7200;
$path = '/';
$domain = '';
$secure = (bool) $config['cookie_secure'];
$http_only = (bool) $config['cookie_httponly'];

if ($config['sess_expiration'] !== FALSE)
{
// Default to 2 years if expiration is "0"
Expand All @@ -99,7 +104,8 @@ protected function initialize()
// Use specified domain
$domain = $config['cookie_domain'];
}
session_set_cookie_params($config['sess_expire_on_close'] ? 0 : $expire, $path, $domain);

session_set_cookie_params($config['sess_expire_on_close'] ? 0 : $expire, $path, $domain, $secure, $http_only);

// Start session
session_start();
Expand Down Expand Up @@ -137,8 +143,12 @@ protected function initialize()
if ($config['sess_time_to_update'] && isset($_SESSION['last_activity'])
&& ($_SESSION['last_activity'] + $config['sess_time_to_update']) < $now)
{
// Regenerate ID, but don't destroy session
$this->sess_regenerate(FALSE);
// Changing the session ID amidst a series of AJAX calls causes problems
if( ! $this->CI->input->is_ajax_request())
{
// Regenerate ID, but don't destroy session
$this->sess_regenerate(FALSE);
}
}

// Set activity time
Expand Down Expand Up @@ -189,7 +199,7 @@ public function sess_destroy()
{
// Clear session cookie
$params = session_get_cookie_params();
setcookie($name, '', time() - 42000, $params['path'], $params['domain']);
setcookie($name, '', time() - 42000, $params['path'], $params['domain'], $params['secure'], $params['httponly']);
unset($_COOKIE[$name]);
}
session_destroy();
Expand Down
15 changes: 9 additions & 6 deletions user_guide_src/source/changelog.rst
Expand Up @@ -153,12 +153,14 @@ Release Date: Not Released

- :doc:`Session Library <libraries/sessions>` changes include:
- Library changed to :doc:`Driver <general/drivers>` with classic Cookie driver as default.
- Added Native PHP Session driver to work with $_SESSION.
- Custom session drivers can be added anywhere in package paths and loaded with Session library.
- Session drivers interchangeable on the fly.
- New tempdata feature allows setting user data items with an expiration time.
- Added default $config['sess_driver'] and $config['sess_valid_drivers'] items to config.php file.
- Cookie driver now respects php.ini's session.gc_probability and session.gc_divisor
- Added Native PHP Session driver to work with ``$_SESSION``.
- Custom drivers can be added anywhere in package paths and be loaded with the library.
- Drivers interchangeable on the fly.
- New **tempdata** feature allows setting user data items with an expiration time.
- Added default ``$config['sess_driver']`` and ``$config['sess_valid_drivers']`` items to *config.php* file.
- Cookie driver now respects php.ini's *session.gc_probability* and *session.gc_divisor* settings.
- Cookie driver now uses HMAC authentication instead of the simple md5 checksum.
- The Cookie driver now also checks authentication on encrypted session data.
- Changed the Cookie driver to select only one row when using database sessions.
- Cookie driver now only writes to database at end of request when using database.
- Cookie driver now uses PHP functions for faster array manipulation when using database.
Expand Down Expand Up @@ -363,6 +365,7 @@ Bug fixes for 3.0
- Fixed a bug (#1709) - :doc:`Email <libraries/email>` headers were broken when using long email subjects and \r\n as CRLF.
- Fixed a bug where ``MB_ENABLED`` was only declared if ``UTF8_ENABLED`` was set to TRUE.
- Fixed a bug where the :doc:`Session Library <libraries/sessions>` accepted cookies with *last_activity* values being in the future.
- Fixed a bug (#1897) - :doc:`Email Library <library/email>` triggered PHP E_WARNING errors when *mail* protocol used and ``to()`` is never called.

Version 2.1.3
=============
Expand Down

0 comments on commit 447d803

Please sign in to comment.