diff options
author | Derek Allard <derek.allard@ellislab.com> | 2008-03-18 01:01:52 +0100 |
---|---|---|
committer | Derek Allard <derek.allard@ellislab.com> | 2008-03-18 01:01:52 +0100 |
commit | 9c4280be80f1f0ad4011ca1ae4f05c89e7963bb9 (patch) | |
tree | 239340c5909db6347254e6fe08b3f5d1b9a40344 | |
parent | 6ef8b69b80093bf706d29df28d108f77acbf9dc0 (diff) |
added hashing to prevent client side data tampering to sessions
-rw-r--r-- | system/libraries/Session.php | 20 | ||||
-rw-r--r-- | user_guide/changelog.html | 1 | ||||
-rw-r--r-- | user_guide/installation/index.html | 2 | ||||
-rw-r--r-- | user_guide/installation/upgrade_162.html | 103 |
4 files changed, 125 insertions, 1 deletions
diff --git a/system/libraries/Session.php b/system/libraries/Session.php index 2cdd50c23..afa43348e 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -196,7 +196,22 @@ class CI_Session { {
$session = $this->CI->encrypt->decode($session);
}
+ else
+ {
+ // encryption was not used, so we need to check the md5 hash
+ $hash = substr($session, strlen($session)-32); // get last 32 chars
+ $session = substr($session, 0, strlen($session)-32);
+ // Does the md5 hash match? This is to prevent manipulation of session data
+ // in userspace
+ if ($hash !== md5($session.$this->CI->config->item('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;
+ }
+ }
+
$session = @unserialize($this->strip_slashes($session));
if ( ! is_array($session) OR ! isset($session['last_activity']))
@@ -284,6 +299,11 @@ class CI_Session { {
$cookie_data = $this->CI->encrypt->encode($cookie_data);
}
+ else
+ {
+ // if encryption is not used, we provide an md5 hash to prevent userside tampering
+ $cookie_data = $cookie_data . md5($cookie_data.$this->CI->config->item('encryption_key'));
+ }
setcookie(
$this->sess_cookie,
diff --git a/user_guide/changelog.html b/user_guide/changelog.html index d90f79aba..b0fa83d6b 100644 --- a/user_guide/changelog.html +++ b/user_guide/changelog.html @@ -68,6 +68,7 @@ Change Log <li>Libraries
<ul>
<li>Added increased security for filename handling in the Upload library.</li>
+ <li>Added increased security for sessions for client-side tampering.</li>
</ul>
</li>
<li>Helpers
diff --git a/user_guide/installation/index.html b/user_guide/installation/index.html index 336f7586b..e925c2175 100644 --- a/user_guide/installation/index.html +++ b/user_guide/installation/index.html @@ -62,7 +62,7 @@ Installation Instructions <ol>
<li>Unzip the package.</li>
<li>Upload the CodeIgniter folders and files to your server. Normally the index.php file will be at your root.</li>
-<li>Open the <dfn>application/config/config.php</dfn> file with a text editor and set your base URL.</li>
+<li>Open the <dfn>application/config/config.php</dfn> file with a text editor and set your base URL. If you intend to use encryption or sessions, set your encryption key.</li>
<li>If you intend to use a database, open the <dfn>application/config/database.php</dfn> file with a text editor and set your database settings.</li>
</ol>
diff --git a/user_guide/installation/upgrade_162.html b/user_guide/installation/upgrade_162.html new file mode 100644 index 000000000..7fd01ea44 --- /dev/null +++ b/user_guide/installation/upgrade_162.html @@ -0,0 +1,103 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+
+<title>CodeIgniter User Guide : Upgrading from 1.6.1 to 1.6.2</title>
+
+<style type='text/css' media='all'>@import url('../userguide.css');</style>
+<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' />
+
+<script type="text/javascript" src="../nav/nav.js"></script>
+<script type="text/javascript" src="../nav/prototype.lite.js"></script>
+<script type="text/javascript" src="../nav/moo.fx.js"></script>
+<script type="text/javascript" src="../nav/user_guide_menu.js"></script>
+
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<meta http-equiv='expires' content='-1' />
+<meta http-equiv= 'pragma' content='no-cache' />
+<meta name='robots' content='all' />
+<meta name='author' content='ExpressionEngine Dev Team' />
+<meta name='description' content='CodeIgniter User Guide' />
+
+</head>
+<body>
+
+<!-- START NAVIGATION -->
+<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div>
+<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle.jpg" width="153" height="44" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div>
+<div id="masthead">
+<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
+<tr>
+<td><h1>CodeIgniter User Guide Version 1.6.1</h1></td>
+<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td>
+</tr>
+</table>
+</div>
+<!-- END NAVIGATION -->
+
+
+<!-- START BREADCRUMB -->
+<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
+<tr>
+<td id="breadcrumb">
+<a href="http://codeigniter.com/">CodeIgniter Home</a> ›
+<a href="../index.html">User Guide Home</a> ›
+Upgrading from 1.6.0 to 1.6.1
+</td>
+<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td>
+</tr>
+</table>
+<!-- END BREADCRUMB -->
+
+<br clear="all" />
+
+
+<!-- START CONTENT -->
+<div id="content">
+
+<h1>Upgrading from 1.6.1 to 1.6.2</h1>
+
+<p>Before performing an update you should take your site offline by replacing the index.php file with a static one.</p>
+
+
+
+<h2>Step 1: Update your CodeIgniter files</h2>
+
+<p>Replace these files and directories in your "system" folder with the new versions:</p>
+
+<ul>
+
+<li><dfn>system/codeigniter</dfn></li>
+<li><dfn>system/database</dfn></li>
+<li><dfn>system/helpers</dfn></li>
+<li><dfn>system/language</dfn></li>
+<li><dfn>system/libraries</dfn></li>
+</ul>
+
+<p class="important"><strong>Note:</strong> If you have any custom developed files in these folders please make copies of them first.</p>
+
+
+<h2>Step 2: Encryption Key</h2>
+<p>If you are using sessions, open up system/application/config.php and verify you've set an encryption key.</p>
+
+
+<h2>Step 3: Update your user guide</h2>
+<p>Please also replace your local copy of the user guide with the new version.</p>
+
+</div>
+<!-- END CONTENT -->
+
+
+<div id="footer">
+<p>
+Previous Topic: <a href="index.html">Installation Instructions</a>
+ ·
+<a href="#top">Top of Page</a> ·
+<a href="../index.html">User Guide Home</a> ·
+Next Topic: <a href="../overview/at_a_glance.html">CodeIgniter at a Glance</a>
+</p>
+<p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006-2008 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p>
+</div>
+
+</body>
+</html>
\ No newline at end of file |