CodeIgniter icon indicating copy to clipboard operation
CodeIgniter copied to clipboard

sess_destroy doesnt destroy userdata.. bug or feature?

Open fluttert opened this issue 14 years ago • 11 comments

Related to https://github.com/EllisLab/CodeIgniter/issues/374

The userguide states that after calling sess_destroy() all data (even flash data) will no longer be available. It just unsets the cookie and deletes the session from the database.. but all userdata is still accessible with normal session functions like: userdata('session_id') and all_userdata();

Why isn't the userdata resetted? Is this by design.. or a small bug? I made a simple controller to illustrate the problem: https://gist.github.com/2580056

1 line of code in the sess_destroy function, would fix this: $this->userdata = array();

Currently I have to call sess_create() , which isn't documented in the user_guide), to destroy the session vars :| :S

PS: Using CI 2.1.0 with MySQL sessions.

fluttert avatar May 02 '12 22:05 fluttert

This bug is still present in 2.1.2.

pawelkg avatar Jul 18 '12 10:07 pawelkg

Yes, the fix was applied to the future 3.0 version.

narfbg avatar Jul 18 '12 10:07 narfbg

Shouldn't this fix be in next 2.1.3 release?

pawelkg avatar Jul 18 '12 10:07 pawelkg

It should've been included in the 2.1.1 release, but seems like nobody thought about it. I'll backport it to the 2.1-stable branch, but it's unlikely that there's a 2.1.3 version released.

narfbg avatar Jul 18 '12 10:07 narfbg

Because the differences between 3.0 and 2.1 will be quite big, and this error is quite significant (in my opinion), this fix should be released same as the current version (2.1.2). In addition, all other minor fixes related to security should be included in the 2.1.3. Not everyone will be able to quickly go from 2.1.x to 3.0. But it's my opinion :)

By the way... shouldn't session data to be reset after deleting it? After set $this->userdata an empty array call $this->sess_create() ?

pawelkg avatar Jul 18 '12 10:07 pawelkg

There are two types of issues that are worth a new release just by themselves - a security issue/improvement or a major bug that breaks a lot of stuff (due to one such, 2.1.1 was re-tagged and re-released).

This one is not of such importance.

narfbg avatar Jul 18 '12 11:07 narfbg

I do not know if you noticed note that I wrote later, so I will write again.

I added this fix to my current project by MY_Session file, and after this: $this->session->set_userdata('example', 'test'); $this->session->sess_destroy(); $this->session->set_flashdata('note', 'Session data destroyed.'); We have a PHP error and flashdata don't work. When creating new (clear) session data just after destroying previous one ($this->sess_create() just behind $this->userdata = array() in Session.php) everything works ok. But I would like notice that I use 2.1.2 with inplemented this fix, not develop branch.

pawelkg avatar Jul 18 '12 12:07 pawelkg

I know what the issue is.

  • The Session library isn't a core class - it's optional (I for one don't use it).
  • I'd be surprised if even 2% of everybody who uses it uses sess_destroy().

For those reasons - it's not worth a new release by itself. As I already said - I'll backport the fix to the 2.1-stable branch, just don't expect a 100% version 2.1.3 release just because of this issue, it would require more than that.

narfbg avatar Jul 18 '12 12:07 narfbg

I understand that. But I'm talking now about consequences of this fix (which I noticed in 2.1.x). After destroy the userdata array, setting (for example) flashdata don't work. I wondering if it isn't logical to set new session after destroying previous one. Even for those 2% :) I don't know how it looks like in 3.0 branch.

pawelkg avatar Jul 18 '12 13:07 pawelkg

When you destroy a session - it no longer exists. You can't use session variables if you don't have a session. You can think of CI_Session::sess_create() and CI_Session::sess_destroy() as session_start() and session_destroy() respectively.

narfbg avatar Jul 18 '12 13:07 narfbg

I know that. :) But while sess_create() is not documented, I would expect that is automatically reloaded. In other words, that even if I delete all session data (by sess_destroy() ), session library will still be operative. But the best way is simply put information about sess_create() to documentation.

Thank for Your time.

pawelkg avatar Jul 18 '12 14:07 pawelkg