Skip to content

Commit 07ac2e6

Browse files
author
Phil Sturgeon
committed
Merge pull request chriskacerguis#171 from Repox/master
Update of CI system files and fixed an issue
2 parents e778d73 + bf060af commit 07ac2e6

File tree

13 files changed

+116
-129
lines changed

13 files changed

+116
-129
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ By default, the HTTP will be `X-API-KEY`. This can be configured in **config/res
146146

147147
## Change Log
148148

149+
### 2.6.2
150+
151+
* Update CodeIgniter files to 2.1.3
152+
* Fixed issue #165
153+
149154
### 2.6.1
150155

151156
* Update CodeIgniter files to 2.1.2

application/libraries/REST_Controller.php

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* @author Phil Sturgeon
1212
* @license http://philsturgeon.co.uk/code/dbad-license
1313
* @link https://github.com/philsturgeon/codeigniter-restserver
14-
* @version 2.6.1
14+
* @version 2.6.2
1515
*/
1616
abstract class REST_Controller extends CI_Controller
1717
{
@@ -60,13 +60,6 @@ abstract class REST_Controller extends CI_Controller
6060
*/
6161
protected $rest = NULL;
6262

63-
/**
64-
* Object to store data about the client sending the request
65-
*
66-
* @var object
67-
*/
68-
protected $client = NULL;
69-
7063
/**
7164
* The arguments for the GET request method
7265
*
@@ -598,12 +591,12 @@ protected function _detect_api_key()
598591
// Find the key from server or arguments
599592
if (($key = isset($this->_args[$api_key_variable]) ? $this->_args[$api_key_variable] : $this->input->server($key_name)))
600593
{
601-
if ( ! ($this->client = $this->rest->db->where(config_item('rest_key_column'), $key)->get(config_item('rest_keys_table'))->row()))
594+
if ( ! ($row = $this->rest->db->where(config_item('rest_key_column'), $key)->get(config_item('rest_keys_table'))->row()))
602595
{
603596
return FALSE;
604597
}
605598

606-
$this->rest->key = $this->client->{config_item('rest_key_column')};
599+
$this->rest->key = $row->{config_item('rest_key_column')};
607600

608601
isset($row->user_id) AND $this->rest->user_id = $row->user_id;
609602
isset($row->level) AND $this->rest->level = $row->level;
@@ -640,8 +633,8 @@ protected function _detect_api_key()
640633
return FALSE;
641634
}
642635
}
643-
644-
return $this->client;
636+
637+
return $row;
645638
}
646639

647640
// No key has been sent

system/core/CodeIgniter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
* @var string
3434
*
3535
*/
36-
define('CI_VERSION', '2.1.2');
36+
define('CI_VERSION', '2.1.3');
3737

3838
/**
3939
* CodeIgniter Branch (Core = TRUE, Reactor = FALSE)

system/core/Common.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ function &load_class($class, $directory = 'libraries', $prefix = 'CI_')
187187
*/
188188
if ( ! function_exists('is_loaded'))
189189
{
190-
function is_loaded($class = '')
190+
function &is_loaded($class = '')
191191
{
192192
static $_is_loaded = array();
193193

system/core/Config.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,12 @@ function load($file = '', $use_sections = FALSE, $fail_gracefully = FALSE)
9999
$found = FALSE;
100100
$loaded = FALSE;
101101

102+
$check_locations = defined('ENVIRONMENT')
103+
? array(ENVIRONMENT.'/'.$file, $file)
104+
: array($file);
105+
102106
foreach ($this->_config_paths as $path)
103107
{
104-
$check_locations = defined('ENVIRONMENT')
105-
? array(ENVIRONMENT.'/'.$file, $file)
106-
: array($file);
107-
108108
foreach ($check_locations as $location)
109109
{
110110
$file_path = $path.'config/'.$location.'.php';
@@ -168,7 +168,7 @@ function load($file = '', $use_sections = FALSE, $fail_gracefully = FALSE)
168168
{
169169
return FALSE;
170170
}
171-
show_error('The configuration file '.$file.'.php'.' does not exist.');
171+
show_error('The configuration file '.$file.'.php does not exist.');
172172
}
173173

174174
return TRUE;
@@ -279,7 +279,7 @@ function site_url($uri = '')
279279
*/
280280
function base_url($uri = '')
281281
{
282-
return $this->slash_item('base_url').ltrim($this->_uri_string($uri),'/');
282+
return $this->slash_item('base_url').ltrim($this->_uri_string($uri), '/');
283283
}
284284

285285
// -------------------------------------------------------------

system/core/Input.php

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ class CI_Input {
7373
*/
7474
protected $headers = array();
7575

76-
7776
/**
7877
* Constructor
7978
*
8079
* Sets whether to globally enable the XSS processing
8180
* and whether to allow the $_GET array
8281
*
82+
* @return void
8383
*/
8484
public function __construct()
8585
{
@@ -306,50 +306,49 @@ function server($index = '', $xss_clean = FALSE)
306306
/**
307307
* Fetch the IP Address
308308
*
309-
* @access public
310309
* @return string
311310
*/
312-
function ip_address()
311+
public function ip_address()
313312
{
314313
if ($this->ip_address !== FALSE)
315314
{
316315
return $this->ip_address;
317316
}
318317

319-
if (config_item('proxy_ips') != '' && $this->server('HTTP_X_FORWARDED_FOR') && $this->server('REMOTE_ADDR'))
318+
$proxy_ips = config_item('proxy_ips');
319+
if ( ! empty($proxy_ips))
320320
{
321-
$proxies = preg_split('/[\s,]/', config_item('proxy_ips'), -1, PREG_SPLIT_NO_EMPTY);
322-
$proxies = is_array($proxies) ? $proxies : array($proxies);
321+
$proxy_ips = explode(',', str_replace(' ', '', $proxy_ips));
322+
foreach (array('HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP', 'HTTP_X_CLIENT_IP', 'HTTP_X_CLUSTER_CLIENT_IP') as $header)
323+
{
324+
if (($spoof = $this->server($header)) !== FALSE)
325+
{
326+
// Some proxies typically list the whole chain of IP
327+
// addresses through which the client has reached us.
328+
// e.g. client_ip, proxy_ip1, proxy_ip2, etc.
329+
if (strpos($spoof, ',') !== FALSE)
330+
{
331+
$spoof = explode(',', $spoof, 2);
332+
$spoof = $spoof[0];
333+
}
323334

324-
$this->ip_address = in_array($_SERVER['REMOTE_ADDR'], $proxies) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
325-
}
326-
elseif ($this->server('REMOTE_ADDR') AND $this->server('HTTP_CLIENT_IP'))
327-
{
328-
$this->ip_address = $_SERVER['HTTP_CLIENT_IP'];
329-
}
330-
elseif ($this->server('REMOTE_ADDR'))
331-
{
332-
$this->ip_address = $_SERVER['REMOTE_ADDR'];
333-
}
334-
elseif ($this->server('HTTP_CLIENT_IP'))
335-
{
336-
$this->ip_address = $_SERVER['HTTP_CLIENT_IP'];
337-
}
338-
elseif ($this->server('HTTP_X_FORWARDED_FOR'))
339-
{
340-
$this->ip_address = $_SERVER['HTTP_X_FORWARDED_FOR'];
341-
}
335+
if ( ! $this->valid_ip($spoof))
336+
{
337+
$spoof = FALSE;
338+
}
339+
else
340+
{
341+
break;
342+
}
343+
}
344+
}
342345

343-
if ($this->ip_address === FALSE)
344-
{
345-
$this->ip_address = '0.0.0.0';
346-
return $this->ip_address;
346+
$this->ip_address = ($spoof !== FALSE && in_array($_SERVER['REMOTE_ADDR'], $proxy_ips, TRUE))
347+
? $spoof : $_SERVER['REMOTE_ADDR'];
347348
}
348-
349-
if (strpos($this->ip_address, ',') !== FALSE)
349+
else
350350
{
351-
$x = explode(',', $this->ip_address);
352-
$this->ip_address = trim(end($x));
351+
$this->ip_address = $_SERVER['REMOTE_ADDR'];
353352
}
354353

355354
if ( ! $this->valid_ip($this->ip_address))
@@ -642,8 +641,8 @@ function _sanitize_globals()
642641
$_SERVER['PHP_SELF'] = strip_tags($_SERVER['PHP_SELF']);
643642

644643

645-
// CSRF Protection check
646-
if ($this->_enable_csrf == TRUE)
644+
// CSRF Protection check on HTTP requests
645+
if ($this->_enable_csrf == TRUE && ! $this->is_cli_request())
647646
{
648647
$this->security->csrf_verify();
649648
}
@@ -837,11 +836,11 @@ public function is_ajax_request()
837836
*
838837
* Test to see if a request was made from the command line
839838
*
840-
* @return boolean
839+
* @return bool
841840
*/
842841
public function is_cli_request()
843842
{
844-
return (php_sapi_name() == 'cli') or defined('STDIN');
843+
return (php_sapi_name() === 'cli' OR defined('STDIN'));
845844
}
846845

847846
}

system/core/Security.php

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -98,26 +98,32 @@ class CI_Security {
9898

9999
/**
100100
* Constructor
101+
*
102+
* @return void
101103
*/
102104
public function __construct()
103105
{
104-
// CSRF config
105-
foreach(array('csrf_expire', 'csrf_token_name', 'csrf_cookie_name') as $key)
106+
// Is CSRF protection enabled?
107+
if (config_item('csrf_protection') === TRUE)
106108
{
107-
if (FALSE !== ($val = config_item($key)))
109+
// CSRF config
110+
foreach (array('csrf_expire', 'csrf_token_name', 'csrf_cookie_name') as $key)
108111
{
109-
$this->{'_'.$key} = $val;
112+
if (FALSE !== ($val = config_item($key)))
113+
{
114+
$this->{'_'.$key} = $val;
115+
}
110116
}
111-
}
112117

113-
// Append application specific cookie prefix
114-
if (config_item('cookie_prefix'))
115-
{
116-
$this->_csrf_cookie_name = config_item('cookie_prefix').$this->_csrf_cookie_name;
117-
}
118+
// Append application specific cookie prefix
119+
if (config_item('cookie_prefix'))
120+
{
121+
$this->_csrf_cookie_name = config_item('cookie_prefix').$this->_csrf_cookie_name;
122+
}
118123

119-
// Set the CSRF hash
120-
$this->_csrf_set_hash();
124+
// Set the CSRF hash
125+
$this->_csrf_set_hash();
126+
}
121127

122128
log_message('debug', "Security Class Initialized");
123129
}
@@ -131,15 +137,14 @@ public function __construct()
131137
*/
132138
public function csrf_verify()
133139
{
134-
// If no POST data exists we will set the CSRF cookie
135-
if (count($_POST) == 0)
140+
// If it's not a POST request we will set the CSRF cookie
141+
if (strtoupper($_SERVER['REQUEST_METHOD']) !== 'POST')
136142
{
137143
return $this->csrf_set_cookie();
138144
}
139145

140146
// Do the tokens exist in both the _POST and _COOKIE arrays?
141-
if ( ! isset($_POST[$this->_csrf_token_name]) OR
142-
! isset($_COOKIE[$this->_csrf_cookie_name]))
147+
if ( ! isset($_POST[$this->_csrf_token_name], $_COOKIE[$this->_csrf_cookie_name]))
143148
{
144149
$this->csrf_show_error();
145150
}
@@ -159,7 +164,7 @@ public function csrf_verify()
159164
$this->_csrf_set_hash();
160165
$this->csrf_set_cookie();
161166

162-
log_message('debug', "CSRF token verified ");
167+
log_message('debug', 'CSRF token verified');
163168

164169
return $this;
165170
}
@@ -176,14 +181,9 @@ public function csrf_set_cookie()
176181
$expire = time() + $this->_csrf_expire;
177182
$secure_cookie = (config_item('cookie_secure') === TRUE) ? 1 : 0;
178183

179-
if ($secure_cookie)
184+
if ($secure_cookie && (empty($_SERVER['HTTPS']) OR strtolower($_SERVER['HTTPS']) === 'off'))
180185
{
181-
$req = isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] : FALSE;
182-
183-
if ( ! $req OR $req == 'off')
184-
{
185-
return FALSE;
186-
}
186+
return FALSE;
187187
}
188188

189189
setcookie($this->_csrf_cookie_name, $this->_csrf_hash, $expire, config_item('cookie_path'), config_item('cookie_domain'), $secure_cookie);
@@ -871,7 +871,6 @@ protected function _csrf_set_hash()
871871
}
872872

873873
}
874-
// END Security Class
875874

876875
/* End of file Security.php */
877-
/* Location: ./system/libraries/Security.php */
876+
/* Location: ./system/libraries/Security.php */

system/database/drivers/oci8/oci8_result.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,16 @@
2626
*/
2727
class CI_DB_oci8_result extends CI_DB_result {
2828

29-
var $stmt_id;
30-
var $curs_id;
31-
var $limit_used;
29+
public $stmt_id;
30+
public $curs_id;
31+
public $limit_used;
3232

3333
/**
3434
* Number of rows in the result set.
3535
*
3636
* Oracle doesn't have a graceful way to retun the number of rows
3737
* so we have to use what amounts to a hack.
3838
*
39-
*
40-
* @access public
4139
* @return integer
4240
*/
4341
public function num_rows()
@@ -53,7 +51,7 @@ public function num_rows()
5351
}
5452
}
5553

56-
return $rowcount;
54+
return $this->num_rows;
5755
}
5856

5957
// --------------------------------------------------------------------

0 commit comments

Comments
 (0)