Skip to content

Commit

Permalink
CI - Updates & Fixes ( v3.1.9 )
Browse files Browse the repository at this point in the history
Codeigniter Updates & Fixes ( v3.1.9 )
  • Loading branch information
Reconix committed Jun 26, 2018
1 parent 1289aa9 commit f814b2a
Show file tree
Hide file tree
Showing 18 changed files with 202 additions and 50 deletions.
2 changes: 1 addition & 1 deletion system/core/CodeIgniter.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
* @var string
*
*/
const CI_VERSION = '3.1.7';
const CI_VERSION = '3.1.9';

/*
* ------------------------------------------------------
Expand Down
18 changes: 14 additions & 4 deletions system/core/Security.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ class CI_Security {
*/
protected $_never_allowed_str = array(
'document.cookie' => '[removed]',
'(document).cookie' => '[removed]',
'document.write' => '[removed]',
'(document).write' => '[removed]',
'.parentNode' => '[removed]',
'.innerHTML' => '[removed]',
'-moz-binding' => '[removed]',
Expand All @@ -152,7 +154,7 @@ class CI_Security {
*/
protected $_never_allowed_regex = array(
'javascript\s*:',
'(document|(document\.)?window)\.(location|on\w*)',
'(\(?document\)?|\(?window\)?(\.document)?)\.(location|on\w*)',
'expression\s*(\(|&\#40;)', // CSS and IE
'vbscript\s*:', // IE, surprise!
'wscript\s*:', // IE
Expand Down Expand Up @@ -542,6 +544,14 @@ public function xss_clean($str, $is_image = FALSE)
$str
);

// Same thing, but for "tag functions" (e.g. eval`some code`)
// See https://github.com/bcit-ci/CodeIgniter/issues/5420
$str = preg_replace(
'#(alert|prompt|confirm|cmd|passthru|eval|exec|expression|system|fopen|fsockopen|file|file_get_contents|readfile|unlink)(\s*)`(.*?)`#si',
'\\1\\2`\\3`',
$str
);

// Final clean up
// This adds a bit of extra precaution in case
// something got through the above filters
Expand Down Expand Up @@ -853,7 +863,7 @@ protected function _sanitize_naughty_html($matches)
// For other tags, see if their attributes are "evil" and strip those
elseif (isset($matches['attributes']))
{
// We'll store the already fitlered attributes here
// We'll store the already filtered attributes here
$attributes = array();

// Attribute-catching pattern
Expand Down Expand Up @@ -927,7 +937,7 @@ protected function _js_link_removal($match)
return str_replace(
$match[1],
preg_replace(
'#href=.*?(?:(?:alert|prompt|confirm)(?:\(|&\#40;)|javascript:|livescript:|mocha:|charset=|window\.|document\.|\.cookie|<script|<xss|d\s*a\s*t\s*a\s*:)#si',
'#href=.*?(?:(?:alert|prompt|confirm)(?:\(|&\#40;|`|&\#96;)|javascript:|livescript:|mocha:|charset=|window\.|\(?document\)?\.|\.cookie|<script|<xss|d\s*a\s*t\s*a\s*:)#si',
'',
$this->_filter_attributes($match[1])
),
Expand Down Expand Up @@ -955,7 +965,7 @@ protected function _js_img_removal($match)
return str_replace(
$match[1],
preg_replace(
'#src=.*?(?:(?:alert|prompt|confirm|eval)(?:\(|&\#40;)|javascript:|livescript:|mocha:|charset=|window\.|document\.|\.cookie|<script|<xss|base64\s*,)#si',
'#src=.*?(?:(?:alert|prompt|confirm|eval)(?:\(|&\#40;|`|&\#96;)|javascript:|livescript:|mocha:|charset=|window\.|\(?document\)?\.|\.cookie|<script|<xss|base64\s*,)#si',
'',
$this->_filter_attributes($match[1])
),
Expand Down
2 changes: 1 addition & 1 deletion system/database/DB_driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -1528,7 +1528,7 @@ protected function _update($table, $values)
return 'UPDATE '.$table.' SET '.implode(', ', $valstr)
.$this->_compile_wh('qb_where')
.$this->_compile_order_by()
.($this->qb_limit ? ' LIMIT '.$this->qb_limit : '');
.($this->qb_limit !== FALSE ? ' LIMIT '.$this->qb_limit : '');
}

// --------------------------------------------------------------------
Expand Down
55 changes: 30 additions & 25 deletions system/database/DB_query_builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ protected function _wh($qb_key, $key, $value = NULL, $type = 'AND ', $escape = N
{
if ($escape === TRUE)
{
$v = ' '.$this->escape($v);
$v = $this->escape($v);
}

if ( ! $this->_has_operator($k))
Expand All @@ -698,10 +698,11 @@ protected function _wh($qb_key, $key, $value = NULL, $type = 'AND ', $escape = N
$k = substr($k, 0, $match[0][1]).($match[1][0] === '=' ? ' IS NULL' : ' IS NOT NULL');
}

$this->{$qb_key}[] = array('condition' => $prefix.$k.$v, 'escape' => $escape);
${$qb_key} = array('condition' => $prefix.$k, 'value' => $v, 'escape' => $escape);
$this->{$qb_key}[] = ${$qb_key};
if ($this->qb_caching === TRUE)
{
$this->{$qb_cache_key}[] = array('condition' => $prefix.$k.$v, 'escape' => $escape);
$this->{$qb_cache_key}[] = ${$qb_key};
$this->qb_cache_exists[] = substr($qb_key, 3);
}

Expand Down Expand Up @@ -834,6 +835,7 @@ protected function _where_in($key = NULL, $values = NULL, $not = FALSE, $type =

$where_in = array(
'condition' => $prefix.$key.$not.' IN('.implode(', ', $where_in).')',
'value' => NULL,
'escape' => $escape
);

Expand Down Expand Up @@ -962,33 +964,34 @@ protected function _like($field, $match = '', $type = 'AND ', $side = 'both', $n
$v = $this->escape_like_str($v);
}

if ($side === 'none')
switch ($side)
{
$like_statement = "{$prefix} {$k} {$not} LIKE '{$v}'";
}
elseif ($side === 'before')
{
$like_statement = "{$prefix} {$k} {$not} LIKE '%{$v}'";
}
elseif ($side === 'after')
{
$like_statement = "{$prefix} {$k} {$not} LIKE '{$v}%'";
}
else
{
$like_statement = "{$prefix} {$k} {$not} LIKE '%{$v}%'";
case 'none':
$v = "'{$v}'";
break;
case 'before':
$v = "'%{$v}'";
break;
case 'after':
$v = "'{$v}%'";
break;
case 'both':
default:
$v = "'%{$v}%'";
break;
}

// some platforms require an escape sequence definition for LIKE wildcards
if ($escape === TRUE && $this->_like_escape_str !== '')
{
$like_statement .= sprintf($this->_like_escape_str, $this->_like_escape_chr);
$v .= sprintf($this->_like_escape_str, $this->_like_escape_chr);
}

$this->qb_where[] = array('condition' => $like_statement, 'escape' => $escape);
$qb_where = array('condition' => "{$prefix} {$k} {$not} LIKE {$v}", 'value' => NULL, 'escape' => $escape);
$this->qb_where[] = $qb_where;
if ($this->qb_caching === TRUE)
{
$this->qb_cache_where[] = array('condition' => $like_statement, 'escape' => $escape);
$this->qb_cache_where[] = $qb_where;
$this->qb_cache_exists[] = 'where';
}
}
Expand All @@ -1013,6 +1016,7 @@ public function group_start($not = '', $type = 'AND ')
$prefix = (count($this->qb_where) === 0 && count($this->qb_cache_where) === 0) ? '' : $type;
$where = array(
'condition' => $prefix.$not.str_repeat(' ', ++$this->qb_where_group_count).' (',
'value' => NULL,
'escape' => FALSE
);

Expand Down Expand Up @@ -1073,6 +1077,7 @@ public function group_end()
$this->qb_where_group_started = FALSE;
$where = array(
'condition' => str_repeat(' ', $this->qb_where_group_count--).')',
'value' => NULL,
'escape' => FALSE
);

Expand Down Expand Up @@ -1433,7 +1438,7 @@ public function count_all_results($table = '', $reset = TRUE)
// --------------------------------------------------------------------

/**
* Get_Where
* get_where()
*
* Allows the where clause, limit and offset to be added directly
*
Expand Down Expand Up @@ -2210,7 +2215,7 @@ public function delete($table = '', $where = '', $limit = NULL, $reset_data = TR
protected function _delete($table)
{
return 'DELETE FROM '.$table.$this->_compile_wh('qb_where')
.($this->qb_limit ? ' LIMIT '.$this->qb_limit : '');
.($this->qb_limit !== FALSE ? ' LIMIT '.$this->qb_limit : '');
}

// --------------------------------------------------------------------
Expand Down Expand Up @@ -2360,7 +2365,7 @@ protected function _compile_select($select_override = FALSE)
.$this->_compile_order_by(); // ORDER BY

// LIMIT
if ($this->qb_limit OR $this->qb_offset)
if ($this->qb_limit !== FALSE OR $this->qb_offset)
{
return $this->_limit($sql."\n");
}
Expand Down Expand Up @@ -2395,7 +2400,7 @@ protected function _compile_wh($qb_key)
}
elseif ($this->{$qb_key}[$i]['escape'] === FALSE)
{
$this->{$qb_key}[$i] = $this->{$qb_key}[$i]['condition'];
$this->{$qb_key}[$i] = $this->{$qb_key}[$i]['condition'].(isset($this->{$qb_key}[$i]['value']) ? ' '.$this->{$qb_key}[$i]['value'] : '');
continue;
}

Expand Down Expand Up @@ -2434,7 +2439,7 @@ protected function _compile_wh($qb_key)
.' '.trim($matches[3]).$matches[4].$matches[5];
}

$this->{$qb_key}[$i] = implode('', $conditions);
$this->{$qb_key}[$i] = implode('', $conditions).(isset($this->{$qb_key}[$i]['value']) ? ' '.$this->{$qb_key}[$i]['value'] : '');
}

return ($qb_key === 'qb_having' ? "\nHAVING " : "\nWHERE ")
Expand Down
15 changes: 14 additions & 1 deletion system/database/drivers/oci8/oci8_driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class CI_DB_oci8_driver extends CI_DB {
*
* @var bool
*/
public $limit_used;
public $limit_used = FALSE;

// --------------------------------------------------------------------

Expand Down Expand Up @@ -685,4 +685,17 @@ protected function _close()
oci_close($this->conn_id);
}

// --------------------------------------------------------------------

/**
* We need to reset our $limit_used hack flag, so it doesn't propagate
* to subsequent queries.
*
* @return void
*/
protected function _reset_select()
{
$this->limit_used = FALSE;
parent::_reset_select();
}
}
7 changes: 3 additions & 4 deletions system/database/drivers/postgre/postgre_driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ public function version()
* and so we'll have to fall back to running a query in
* order to get it.
*/
return isset($pg_version['server'])
? $this->data_cache['version'] = $pg_version['server']
return (isset($pg_version['server']) && preg_match('#^(\d+\.\d+)#', $pg_version['server'], $match))
? $this->data_cache['version'] = $match[1]
: parent::version();
}

Expand Down Expand Up @@ -354,8 +354,7 @@ public function affected_rows()
*/
public function insert_id()
{
$v = pg_version($this->conn_id);
$v = isset($v['server']) ? $v['server'] : 0; // 'server' key is only available since PosgreSQL 7.4
$v = $this->version();

$table = (func_num_args() > 0) ? func_get_arg(0) : NULL;
$column = (func_num_args() > 1) ? func_get_arg(1) : NULL;
Expand Down
6 changes: 3 additions & 3 deletions system/helpers/html_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ function img($src = '', $index_page = FALSE, $attributes = '')
}
else
{
$img .= ' src="'.get_instance()->config->slash_item('base_url').$v.'"';
$img .= ' src="'.get_instance()->config->base_url($v).'"';
}
}
else
Expand Down Expand Up @@ -292,7 +292,7 @@ function link_tag($href = '', $rel = 'stylesheet', $type = 'text/css', $title =
}
else
{
$link .= 'href="'.$CI->config->slash_item('base_url').$v.'" ';
$link .= 'href="'.$CI->config->base_url($v).'" ';
}
}
else
Expand All @@ -313,7 +313,7 @@ function link_tag($href = '', $rel = 'stylesheet', $type = 'text/css', $title =
}
else
{
$link .= 'href="'.$CI->config->slash_item('base_url').$href.'" ';
$link .= 'href="'.$CI->config->base_url($href).'" ';
}

$link .= 'rel="'.$rel.'" type="'.$type.'" ';
Expand Down
2 changes: 1 addition & 1 deletion system/helpers/url_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ function auto_link($str, $type = 'both', $popup = FALSE)
if ($type !== 'email' && preg_match_all('#(\w*://|www\.)[a-z0-9]+(-+[a-z0-9]+)*(\.[a-z0-9]+(-+[a-z0-9]+)*)+(/([^\s()<>;]+\w)?/?)?#i', $str, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER))
{
// Set our target HTML if using popup links.
$target = ($popup) ? ' target="_blank"' : '';
$target = ($popup) ? ' target="_blank" rel="noopener"' : '';

// We process the links in reverse order (last -> first) so that
// the returned string offsets from preg_match_all() are not
Expand Down
30 changes: 25 additions & 5 deletions system/libraries/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -1035,10 +1035,14 @@ public function valid_email($email)
if (function_exists('idn_to_ascii') && strpos($email, '@'))
{
list($account, $domain) = explode('@', $email, 2);
$domain = is_php('5.4')
$domain = defined('INTL_IDNA_VARIANT_UTS46')
? idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46)
: idn_to_ascii($domain);
$email = $account.'@'.$domain;

if ($domain !== FALSE)
{
$email = $account.'@'.$domain;
}
}

return (bool) filter_var($email, FILTER_VALIDATE_EMAIL);
Expand Down Expand Up @@ -1856,10 +1860,14 @@ protected function _validate_email_for_shell(&$email)
if (function_exists('idn_to_ascii') && strpos($email, '@'))
{
list($account, $domain) = explode('@', $email, 2);
$domain = is_php('5.4')
$domain = defined('INTL_IDNA_VARIANT_UTS46')
? idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46)
: idn_to_ascii($domain);
$email = $account.'@'.$domain;

if ($domain !== FALSE)
{
$email = $account.'@'.$domain;
}
}

return (filter_var($email, FILTER_VALIDATE_EMAIL) === $email && preg_match('#\A[a-z0-9._+-]+@[a-z0-9.-]{1,253}\z#i', $email));
Expand Down Expand Up @@ -2074,7 +2082,19 @@ protected function _smtp_connect()
$this->_send_command('hello');
$this->_send_command('starttls');

$crypto = stream_socket_enable_crypto($this->_smtp_connect, TRUE, STREAM_CRYPTO_METHOD_TLS_CLIENT);
/**
* STREAM_CRYPTO_METHOD_TLS_CLIENT is quite the mess ...
*
* - On PHP <5.6 it doesn't even mean TLS, but SSL 2.0, and there's no option to use actual TLS
* - On PHP 5.6.0-5.6.6, >=7.2 it means negotiation with any of TLS 1.0, 1.1, 1.2
* - On PHP 5.6.7-7.1.* it means only TLS 1.0
*
* We want the negotiation, so we'll force it below ...
*/
$method = is_php('5.6')
? STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT | STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT | STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT
: STREAM_CRYPTO_METHOD_TLS_CLIENT;
$crypto = stream_socket_enable_crypto($this->_smtp_connect, TRUE, $method);

if ($crypto !== TRUE)
{
Expand Down
8 changes: 6 additions & 2 deletions system/libraries/Form_validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -1231,10 +1231,14 @@ public function valid_email($str)
{
if (function_exists('idn_to_ascii') && preg_match('#\A([^@]+)@(.+)\z#', $str, $matches))
{
$domain = is_php('5.4')
$domain = defined('INTL_IDNA_VARIANT_UTS46')
? idn_to_ascii($matches[2], 0, INTL_IDNA_VARIANT_UTS46)
: idn_to_ascii($matches[2]);
$str = $matches[1].'@'.$domain;

if ($domain !== FALSE)
{
$str = $matches[1].'@'.$domain;
}
}

return (bool) filter_var($str, FILTER_VALIDATE_EMAIL);
Expand Down
5 changes: 4 additions & 1 deletion system/libraries/Image_lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,10 @@ public function image_process_gd($action = 'resize')
imagedestroy($dst_img);
imagedestroy($src_img);

chmod($this->full_dst_path, $this->file_permissions);
if ($this->dynamic_output !== TRUE)
{
chmod($this->full_dst_path, $this->file_permissions);
}

return TRUE;
}
Expand Down
2 changes: 1 addition & 1 deletion system/libraries/Session/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ public function get_temp_keys()
// ------------------------------------------------------------------------

/**
* Unmark flash
* Unmark temp
*
* @param mixed $key Session data key(s)
* @return void
Expand Down
Loading

0 comments on commit f814b2a

Please sign in to comment.