note 94398 deleted from function.setcookie by cmb

From: Date: Sun, 03 Mar 2019 11:32:14 +0000
Subject: note 94398 deleted from function.setcookie by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-210305@lists.php.net to get a copy of this message
Note Submitter: dbessoudo at gmail dot com ---- setcookie - value = "deleted" on IE setcookie(session_name(), '', time()-42000, '/'); When "setcookie" is passed an empty value (ie, ''), it changes the value to the string "deleted" and sets the date to exactly one year and one second in the past, ignoring the expiration parameter.* So, I'm guessing that if a client machine has its time set to more than a year in the past or if the browser is somehow broken, then a site visitor could potentially send a PHPSESSID with a value of "deleted". This will cause PHP to create a "sess_deleted" file in the sessions directory. In my case, I was seeing several incidents per minute, with each user clobbering the other's session data causing all kinds of security and identity issues. Two changes seemed to have solved the problem: 1) Use session_id() in place of '' in setcookie, as well as pick a date that's far in the past (in this case Jan 1, 1970, 8:00:01AM): setcookie(session_name(), session_id(), 1, '/'); 2) Use session_regenerate_id() when logging a user in or otherwise changing their authority level. Hope this helps somebody. Rob * Here is the relevant code in head.c: if (value && value_len == 0) { /* * MSIE doesn't delete a cookie when you set it to a null value * so in order to force cookies to be deleted, even on MSIE, we * pick an expiry date 1 year and 1 second in the past */ time_t t = time(NULL) - 31536001; dt = php_format_date("D, d-M-Y H:i:s T", sizeof("D, d-M-Y H:i:s T")-1, t, 0 TSRMLS_CC); sprintf(cookie, "Set-Cookie: %s=deleted; expires=%s", name, dt);

« previous php.notes (#210305) next »