Skip to content

Commit da85941

Browse files
committed
[ci skip] Backport security-related changes from 3.0
1 parent 3949a88 commit da85941

File tree

4 files changed

+31
-10
lines changed

4 files changed

+31
-10
lines changed

application/config/config.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010
|
1111
| http://example.com/
1212
|
13-
| If this is not set then CodeIgniter will guess the protocol, domain and
14-
| path to your installation.
13+
| If this is not set then CodeIgniter will try to guess the protocol, domain
14+
| and path to your installation. However, you should always configure this
15+
| explicitly and never rely on auto-guessing, especially in production
16+
| environments.
1517
|
1618
*/
17-
$config['base_url'] = '';
19+
$config['base_url'] = '';
1820

1921
/*
2022
|--------------------------------------------------------------------------

system/core/Config.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,13 @@ function __construct()
6767
// Set the base_url automatically if none was provided
6868
if ($this->config['base_url'] == '')
6969
{
70-
if (isset($_SERVER['HTTP_HOST']))
70+
// The regular expression is only a basic validation for a valid "Host" header.
71+
// It's not exhaustive, only checks for valid characters.
72+
if (isset($_SERVER['HTTP_HOST']) && preg_match('/^((\[[0-9a-f:]+\])|(\d{1,3}(\.\d{1,3}){3})|[a-z0-9\-\.]+)(:\d+)?$/i', $_SERVER['HTTP_HOST']))
7173
{
7274
$base_url = (empty($_SERVER['HTTPS']) OR strtolower($_SERVER['HTTPS']) === 'off') ? 'http' : 'https';
7375
$base_url .= '://'. $_SERVER['HTTP_HOST'];
74-
$base_url .= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);
76+
$base_url .= substr($_SERVER['SCRIPT_NAME'], 0, strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME'])));
7577
}
7678

7779
else

system/core/Security.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -530,19 +530,19 @@ public function entity_decode($str, $charset='UTF-8')
530530
{
531531
$_entities[':'] = ':';
532532
$_entities['('] = '(';
533-
$_entities[')'] = '&rpar';
533+
$_entities[')'] = ')';
534534
$_entities["\n"] = '&newline;';
535535
$_entities["\t"] = '&tab;';
536536
}
537537
}
538538

539539
$replace = array();
540540
$matches = array_unique(array_map('strtolower', $matches[0]));
541-
for ($i = 0, $c = count($matches); $i < $c; $i++)
541+
foreach ($matches as &$match)
542542
{
543-
if (($char = array_search($matches[$i].';', $_entities, TRUE)) !== FALSE)
543+
if (($char = array_search($match.';', $_entities, TRUE)) !== FALSE)
544544
{
545-
$replace[$matches[$i]] = $char;
545+
$replace[$match] = $char;
546546
}
547547
}
548548

@@ -644,7 +644,7 @@ protected function _compact_exploded_words($matches)
644644
protected function _remove_evil_attributes($str, $is_image)
645645
{
646646
// All javascript event handlers (e.g. onload, onclick, onmouseover), style, and xmlns
647-
$evil_attributes = array('on\w*', 'style', 'xmlns', 'formaction', 'form', 'xlink:href');
647+
$evil_attributes = array('on\w*', 'style', 'xmlns', 'formaction', 'form', 'xlink:href', 'FSCommand', 'seekSegmentTime');
648648

649649
if ($is_image === TRUE)
650650
{

user_guide/changelog.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,23 @@
5757

5858
<h1>Change Log</h1>
5959

60+
<h2>Version 2.2.2</h2>
61+
<p>Release Date: Not Released</p>
62+
63+
<ul>
64+
<li>General Changes</li>
65+
<ul>
66+
<li>Added HTTP "Host" header character validation to prevent cache poisoning attacks when <kbd>base_url</kbd> auto-detection is used.</li>
67+
<li>Added <kbd>FSCommand</kbd> and <kbd>seekSegmentTime</kbd> to the "evil attributes" list in <samp>CI_Security::xss_clean()</samp>.</li>
68+
</ul>
69+
</li>
70+
</ul>
71+
72+
<h3>Bug fixes:</h3>
73+
<ul>
74+
<li>Fixed a bug (#3665) - <samp>CI_Security::entity_decode()</samp> triggered warnings under some circumstances.</li>
75+
</ul>
76+
6077
<h2>Version 2.2.1</h2>
6178
<p>Release Date: January 22, 2015</p>
6279

0 commit comments

Comments
 (0)