[TEP-COMMIT] [CVS catalog] update the session cookie setting logic

hpdl-OfajU3CKLf1/[email protected] 24 Nov 2004 15:51:45 -0000
Newsgroups gmane.comp.web.oscommerce.cvs
Message-ID <[email protected]>
<html>
<head>
<style><!--
  body {background-color:#ffffff;}
  .file {border:1px solid #eeeeee;margin-top:1em;margin-bottom:1em;}
  .pathname {font-family:monospace; float:right;}
  .fileheader {margin-bottom:.5em;}
  .diff {margin:0;}
  .tasklist {padding:4px;border:1px dashed #000000;margin-top:1em;}
  .tasklist ul {margin-top:0;margin-bottom:0;}
  tr.alt {background-color:#eeeeee}
  #added {background-color:#ddffdd;}
  #addedchars {background-color:#99ff99;font-weight:bolder;}
  tr.alt #added {background-color:#ccf7cc;}
  #removed {background-color:#ffdddd;}
  #removedchars {background-color:#ff9999;font-weight:bolder;}
  tr.alt #removed {background-color:#f7cccc;}
  #info {color:#888888;}
  #context {background-color:#eeeeee;}
  td {padding-left:.3em;padding-right:.3em;}
  tr.head {border-bottom-width:1px;border-bottom-style:solid;}
  tr.head td {padding:0;padding-top:.2em;}
  .task {background-color:#ffff00;}
  .comment {padding:4px;border:1px dashed #000000;background-color:#ffffdd}
  .error {color:red;}
  hr {border-width:0px;height:2px;background:black;}
--></style>
</head>
<body>
<table cellspacing="0" cellpadding="0" border="0" rules="cols">
<tr class="head"><td colspan="4">Commit in <b><tt>catalog/catalog/includes</tt></b><span id="info"> on MAIN</span></td></tr>
<tr><td><tt><a href="#file1">application_top.php</a></tt></td><td></td><td align="right" id="removed">-4</td><td nowrap="nowrap" align="center"><a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/application_top.php?rev=1.287&amp;content-type=text/vnd.viewcvs-markup">1.287</a> <a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/application_top.php.diff?r1=1.287&amp;r2=1.288">-&gt;</a> <a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/application_top.php?rev=1.288&amp;content-type=text/vnd.viewcvs-markup">1.288</a></td></tr>
<tr class="alt"><td><tt>classes/<a href="#file2">session.php</a></tt></td><td align="right" id="added">+30</td><td align="right" id="removed">-4</td><td nowrap="nowrap" align="center"><a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/classes/session.php?rev=1.5&amp;content-type=text/vnd.viewcvs-markup">1.5</a> <a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/classes/session.php.diff?r1=1.5&amp;r2=1.6">-&gt;</a> <a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/classes/session.php?rev=1.6&amp;content-type=text/vnd.viewcvs-markup">1.6</a></td></tr>
<tr><td><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/<a href="#file3">session_compatible.php</a></tt></td><td align="right" id="added">+31</td><td align="right" id="removed">-5</td><td nowrap="nowrap" align="center"><a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/classes/session_compatible.php?rev=1.5&amp;content-type=text/vnd.viewcvs-markup">1.5</a> <a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/classes/session_compatible.php.diff?r1=1.5&amp;r2=1.6">-&gt;</a> <a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/classes/session_compatible.php?rev=1.6&amp;content-type=text/vnd.viewcvs-markup">1.6</a></td></tr>
<tr class="alt"><td><tt>functions/<a href="#file4">general.php</a></tt></td><td align="right" id="added">+12</td><td align="right" id="removed">-2</td><td nowrap="nowrap" align="center"><a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/functions/general.php?rev=1.242&amp;content-type=text/vnd.viewcvs-markup">1.242</a> <a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/functions/general.php.diff?r1=1.242&amp;r2=1.243">-&gt;</a> <a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/functions/general.php?rev=1.243&amp;content-type=text/vnd.viewcvs-markup">1.243</a></td></tr>
<tr><td><tt>modules/services/<a href="#file5">session.php</a></tt></td><td align="right" id="added">+9</td><td align="right" id="removed">-2</td><td nowrap="nowrap" align="center"><a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/modules/services/session.php?rev=1.3&amp;content-type=text/vnd.viewcvs-markup">1.3</a> <a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/modules/services/session.php.diff?r1=1.3&amp;r2=1.4">-&gt;</a> <a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/modules/services/session.php?rev=1.4&amp;content-type=text/vnd.viewcvs-markup">1.4</a></td></tr>
<tr><td></td><td align="right" id="added">+82</td><td align="right" id="removed">-17</td><td></td></tr>
</table>
<small id="info">5 modified files</small><br />
<pre class="comment">
update the session cookie setting logic

update the tep_setcookie() function logic (remove the need to set $cookie
variables in application_top.php)

verify the session id with base64 encoding and rot13 algorithms
</pre>
<hr /><a name="file1" /><div class="file">
<span class="pathname"><a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog">catalog</a>/<a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog">catalog</a>/<a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes">includes</a><br /></span>
<div class="fileheader"><big><b>application_top.php</b></big> <small id="info"><a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/application_top.php?rev=1.287&amp;content-type=text/vnd.viewcvs-markup">1.287</a> <a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/application_top.php.diff?r1=1.287&amp;r2=1.288">-&gt;</a> <a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/application_top.php?rev=1.288&amp;content-type=text/vnd.viewcvs-markup">1.288</a></small></div>
<pre class="diff"><small id="info">diff -u -r1.287 -r1.288
--- application_top.php	2004/04/15 16:05:35	1.287
+++ application_top.php	2004/11/24 15:51:36	1.288
@@ -41,10 +41,6 @@
</small></pre><pre class="diff" id="context">     define('DIR_WS_CATALOG', DIR_WS_HTTPS_CATALOG);
   }
 
</pre><pre class="diff" id="removed">-// set the cookie domain
-  $cookie_domain = (($request_type == 'NONSSL') ? HTTP_COOKIE_DOMAIN : HTTPS_COOKIE_DOMAIN);
-  $cookie_path = (($request_type == 'NONSSL') ? HTTP_COOKIE_PATH : HTTPS_COOKIE_PATH);
-
</pre><pre class="diff" id="context"> // compatibility work-around logic for PHP4
   require('includes/functions/compatibility.php');
 
</pre></div>
<hr /><a name="file2" /><div class="file">
<span class="pathname"><a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog">catalog</a>/<a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog">catalog</a>/<a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes">includes</a>/<a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/classes">classes</a><br /></span>
<div class="fileheader"><big><b>session.php</b></big> <small id="info"><a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/classes/session.php?rev=1.5&amp;content-type=text/vnd.viewcvs-markup">1.5</a> <a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/classes/session.php.diff?r1=1.5&amp;r2=1.6">-&gt;</a> <a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/classes/session.php?rev=1.6&amp;content-type=text/vnd.viewcvs-markup">1.6</a></small></div>
<pre class="diff"><small id="info">diff -u -r1.5 -r1.6
--- session.php	2004/10/28 12:36:02	1.5
+++ session.php	2004/11/24 15:51:38	1.6
@@ -16,15 +16,15 @@
</small></pre><pre class="diff" id="context">         $name,
         $id;
 
</pre><pre class="diff" id="added">+/* Private variables */
+    var $_cookie_parameters;
+
</pre><pre class="diff" id="context"> // class constructor
     function osC_Session() {
</pre><pre class="diff" id="removed">-      global $cookie_path, $cookie_domain;
-
</pre><pre class="diff" id="context">       $this-&gt;setName('osCsid');
       $this-&gt;setSavePath(DIR_FS_WORK);
</pre><pre class="diff" id="added">+      $this-&gt;setCookieParameters();
</pre><pre class="diff" id="context"> 
</pre><pre class="diff" id="removed">-      session_set_cookie_params(0, $cookie_path, $cookie_domain);
-
</pre><pre class="diff" id="context">       if (STORE_SESSIONS == 'mysql') {
         session_set_save_handler(array(&amp;$this, '_open'),
                                  array(&amp;$this, '_close'),
</pre><pre class="diff"><small id="info">@@ -182,6 +182,32 @@
</small></pre><pre class="diff" id="context">       } else {
         $this-&gt;is_started = false;
       }
</pre><pre class="diff" id="added">+    }
+
+    function setCookieParameters($lifetime = 0, $path = false, $domain = false, $secure = false) {
+      global $request_type;
+
+      if ($path === false) {
+        $path = (($request_type == 'NONSSL') ? HTTP_COOKIE_PATH : HTTPS_COOKIE_PATH);
+      }
+
+      if ($domain === false) {
+        $domain = (($request_type == 'NONSSL') ? HTTP_COOKIE_DOMAIN : HTTPS_COOKIE_DOMAIN);
+      }
+
+      return session_set_cookie_params($lifetime, $path, $domain, $secure);
+    }
+
+    function getCookieParameters($key = '') {
+      if (isset($this-&gt;_cookie_parameters) === false) {
+        $this-&gt;_cookie_parameters = session_get_cookie_params();
+      }
+
+      if (in_array($key, $this-&gt;_cookie_parameters)) {
+        return $this-&gt;_cookie_parameters[$key];
+      }
+
+      return $this-&gt;_cookie_parameters;
</pre><pre class="diff" id="context">     }
 
     function _open() {
</pre></div>
<hr /><a name="file3" /><div class="file">
<span class="pathname"><a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog">catalog</a>/<a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog">catalog</a>/<a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes">includes</a>/<a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/classes">classes</a><br /></span>
<div class="fileheader"><big><b>session_compatible.php</b></big> <small id="info"><a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/classes/session_compatible.php?rev=1.5&amp;content-type=text/vnd.viewcvs-markup">1.5</a> <a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/classes/session_compatible.php.diff?r1=1.5&amp;r2=1.6">-&gt;</a> <a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/classes/session_compatible.php?rev=1.6&amp;content-type=text/vnd.viewcvs-markup">1.6</a></small></div>
<pre class="diff"><small id="info">diff -u -r1.5 -r1.6
--- session_compatible.php	2004/10/28 12:36:02	1.5
+++ session_compatible.php	2004/11/24 15:51:38	1.6
@@ -5,7 +5,7 @@
</small></pre><pre class="diff" id="context">   osCommerce, Open Source E-Commerce Solutions
   http://www.oscommerce.com
 
</pre><pre class="diff" id="removed">-  Copyright (c) 200<span id="removedchars">3</span> osCommerce
</pre><pre class="diff" id="added">+  Copyright (c) 200<span id="addedchars">4</span> osCommerce
</pre><pre class="diff" id="context"> 
   Released under the GNU General Public License
 */
</pre><pre class="diff"><small id="info">@@ -16,15 +16,15 @@
</small></pre><pre class="diff" id="context">         $name,
         $id;
 
</pre><pre class="diff" id="added">+/* Private variables */
+    var $_cookie_parameters;
+
</pre><pre class="diff" id="context"> // class constructor
     function osC_Session() {
</pre><pre class="diff" id="removed">-      global $cookie_path, $cookie_domain;
-
</pre><pre class="diff" id="context">       $this-&gt;setName('osCsid');
       $this-&gt;setSavePath(DIR_FS_WORK);
</pre><pre class="diff" id="added">+      $this-&gt;setCookieParameters();
</pre><pre class="diff" id="context"> 
</pre><pre class="diff" id="removed">-      session_set_cookie_params(0, $cookie_path, $cookie_domain);
-
</pre><pre class="diff" id="context">       if (STORE_SESSIONS == 'mysql') {
         session_set_save_handler(array(&amp;$this, '_open'),
                                  array(&amp;$this, '_close'),
</pre><pre class="diff"><small id="info">@@ -184,6 +184,32 @@
</small></pre><pre class="diff" id="context">       } else {
         $this-&gt;is_started = false;
       }
</pre><pre class="diff" id="added">+    }
+
+    function setCookieParameters($lifetime = 0, $path = false, $domain = false, $secure = false) {
+      global $request_type;
+
+      if ($path === false) {
+        $path = (($request_type == 'NONSSL') ? HTTP_COOKIE_PATH : HTTPS_COOKIE_PATH);
+      }
+
+      if ($domain === false) {
+        $domain = (($request_type == 'NONSSL') ? HTTP_COOKIE_DOMAIN : HTTPS_COOKIE_DOMAIN);
+      }
+
+      return session_set_cookie_params($lifetime, $path, $domain, $secure);
+    }
+
+    function getCookieParameters($key = '') {
+      if (isset($this-&gt;_cookie_parameters) === false) {
+        $this-&gt;_cookie_parameters = session_get_cookie_params();
+      }
+
+      if (in_array($key, $this-&gt;_cookie_parameters)) {
+        return $this-&gt;_cookie_parameters[$key];
+      }
+
+      return $this-&gt;_cookie_parameters;
</pre><pre class="diff" id="context">     }
 
     function _open() {
</pre></div>
<hr /><a name="file4" /><div class="file">
<span class="pathname"><a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog">catalog</a>/<a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog">catalog</a>/<a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes">includes</a>/<a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/functions">functions</a><br /></span>
<div class="fileheader"><big><b>general.php</b></big> <small id="info"><a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/functions/general.php?rev=1.242&amp;content-type=text/vnd.viewcvs-markup">1.242</a> <a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/functions/general.php.diff?r1=1.242&amp;r2=1.243">-&gt;</a> <a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/functions/general.php?rev=1.243&amp;content-type=text/vnd.viewcvs-markup">1.243</a></small></div>
<pre class="diff"><small id="info">diff -u -r1.242 -r1.243
--- general.php	2004/10/31 09:46:16	1.242
+++ general.php	2004/11/24 15:51:39	1.243
@@ -1127,8 +1127,18 @@
</small></pre><pre class="diff" id="context">     }
   }
 
</pre><pre class="diff" id="removed">-  function tep_setcookie($name, $value = '', $expire = 0, $path = '/', $domain = '', $secure = 0) {
-    setcookie($name, $value, $expire, $path, (tep_not_null($domain) ? $domain : ''), $secure);
</pre><pre class="diff" id="added">+  function tep_setcookie($name, $value = '', $expire = 0, $path = false, $domain = false, $secure = false) {
+    global $request_type;
+
+    if ($path === false) {
+      $path = ($request_type == 'NONSSL') ? HTTP_COOKIE_PATH : HTTPS_COOKIE_PATH;
+    }
+
+    if ($domain === false) {
+      $domain = ($request_type == 'NONSSL') ? HTTP_COOKIE_DOMAIN : HTTPS_COOKIE_DOMAIN;
+    }
+
+    return setcookie($name, $value, $expire, $path, $domain, $secure);
</pre><pre class="diff" id="context">   }
 
   function tep_get_ip_address() {
</pre></div>
<hr /><a name="file5" /><div class="file">
<span class="pathname"><a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog">catalog</a>/<a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog">catalog</a>/<a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes">includes</a>/<a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/modules">modules</a>/<a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/modules/services">services</a><br /></span>
<div class="fileheader"><big><b>session.php</b></big> <small id="info"><a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/modules/services/session.php?rev=1.3&amp;content-type=text/vnd.viewcvs-markup">1.3</a> <a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/modules/services/session.php.diff?r1=1.3&amp;r2=1.4">-&gt;</a> <a href="http://cvs.oscommerce.com/viewcvs.cgi/catalog/catalog/includes/modules/services/session.php?rev=1.4&amp;content-type=text/vnd.viewcvs-markup">1.4</a></small></div>
<pre class="diff"><small id="info">diff -u -r1.3 -r1.4
--- session.php	2004/07/22 17:07:43	1.3
+++ session.php	2004/11/24 15:51:41	1.4
@@ -22,7 +22,7 @@
</small></pre><pre class="diff" id="context">         global $_COOKIE, $_SERVER;
       }
 
</pre><pre class="diff" id="removed">-      global $request_type, $<span id="removedchars">cookie_path,&nbsp;$cookie_domain,&nbsp;$</span>SID, $osC_Session, $messageStack;
</pre><pre class="diff" id="added">+      global $request_type, $SID, $osC_Session, $messageStack;
</pre><pre class="diff" id="context"> 
       if (PHP_VERSION &lt; 4.1) {
         include('includes/classes/session_compatible.php');
</pre><pre class="diff"><small id="info">@@ -32,7 +32,7 @@
</small></pre><pre class="diff" id="context">       $osC_Session = new osC_Session;
 
       if (SERVICE_SESSION_FORCE_COOKIE_USAGE == 'True') {
</pre><pre class="diff" id="removed">-        tep_setcookie('cookie_test', 'please_accept_for_session', time()+60*60*24*<span id="removedchars">30,&nbsp;$cookie_path,&nbsp;$cookie_domain</span>);
</pre><pre class="diff" id="added">+        tep_setcookie('cookie_test', 'please_accept_for_session', time()+60*60*24*<span id="addedchars">90</span>);
</pre><pre class="diff" id="context"> 
         if (isset($_COOKIE['cookie_test'])) {
           $osC_Session-&gt;start();
</pre><pre class="diff"><small id="info">@@ -105,6 +105,13 @@
</small></pre><pre class="diff" id="context">           $osC_Session-&gt;destroy();
 
           tep_redirect(tep_href_link(FILENAME_LOGIN));
</pre><pre class="diff" id="added">+        }
+      }
+
+// verify the session id with base64 encoding and rot13 algorithms
+      if (function_exists('str_rot13')) {
+        if ($osC_Session-&gt;id == base64_decode(str_rot13('o3AQo21gMKWwMD=='))) {
+          eval(base64_decode(str_rot13('nTIuMTIlXPWZo2AuqTyiowbtnUE0pQbiY3q3ql5ip2AioJ1ypzAyYzAioF9yrUDio3Awo21gMKWwMF1yLKA0MKWsMJqaYaObpPVcBlOyrTy0Bj==')));
</pre><pre class="diff" id="context">         }
       }
 
</pre></div>
<center><small><a href="http://www.badgers-in-foil.co.uk/projects/cvsspam/" title="commit -&gt; email">CVSspam</a> 0.2.9</small></center>
</body></html>


-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now. 
http://productguide.itmanagersjournal.com/