Welcome Guest, Not a member yet? Register   Sign In
how does session data manipulation work with cookies?
#1

[eluser]MikeW1911[/eluser]
Around 31:15 of this video: codeigniter security tutorial, the guy changes the user_id session value to the admin user id and gains full access. I'm not sure what he did to change the session value.

If I change my cookie values using a developer tool, would Codeigniter simply read the cookie values and change the corresponding session value?
#2

[eluser]WanWizard[/eluser]
CI can encrypt the cookie payload by setting $this->session->sess_encrypt_cookie to TRUE (or in the config).

Unfortunately, up until the latest release (2.1.0), the default is FALSE, which will open your app for this vulnerability.

imho opinion it should be TRUE by default to avoid beginners making errors like this, if you insist on using cookie-only sessions (which ideally you should avoid, don't send session data to the client).
#3

[eluser]MikeW1911[/eluser]
If I use the native PHP session method using session_start() and the $_SESSION array do I avoid the problem of clients editing the cookie file to change session values (other than the session id)?
#4

[eluser]WanWizard[/eluser]
No.

Native sessions are inheritly insecure, and even more so on a lot of shared hosts. CI doesn't come with it's own session library for nothing. Wink

CI's session library is secure, but unfortunately the defaults are not the best they could have picked. So in your application/config/config.php:
Code:
$config['sess_cookie_name']  = 'cisession'; // get rid of the underscore, IE doesn't like it
$config['sess_encrypt_cookie'] = TRUE; // do encrypt the cookie
$config['sess_use_database'] = TRUE; // store session data in the database, not in the cookie
$config['sess_match_ip']  = FALSE; // if you don't have users with alternating proxies, set this to TRUE too
and create the session database as documented in the user guide.
#5

[eluser]MikeW1911[/eluser]
For the sake of learning, can you explain in detail why session data manipulation is possible without cookie encryption?
#6

[eluser]CroNiX[/eluser]
Because the raw data in plain text is in a cookie, on your computer, which you can edit. Picture someone storing the user level that you can just change to "admin" or something by editing the cookie.

If you use the database, it stores the data in the database and only stores the session id in the cookie, so they can't manipulate it. And if the id is encrypted, it will be really hard for them to break figure it out.

Beyond that, cookies are limited to holding a total of 4k of data, which isn't very much for apps that require larger session storage, which the database offers.
#7

[eluser]MikeW1911[/eluser]
I tried changing the cookie value for my test website, but the corresponding session value was unset. For example, in the cookie, I changed "user_id" to 2, but the "user_id" value in the session array was unset. Without cookie encryption, there still seems be an md5 hash value associated with the cookie. So someone has to do more than just changing the cookie value to manipulate session array values?
#8

[eluser]InsiteFX[/eluser]
CI sessions encrypts the session cookie!

Look at the ./system/libraries/Session.php file.
#9

[eluser]MikeW1911[/eluser]
Can you please explain 31:15 of this video then: codeigniter security tutorial
#10

[eluser]CroNiX[/eluser]
It gets encrypted automatically if you use the database for session storage. If you aren't you need to manually turn encryption on for sessions (which should be the default setting, IMO).

Just use database sessions with encryption. It's just a lot more secure because then all the user has access to is an encrypted session ID with no other data since that part is in the database, so they can't manipulate it.




Theme © iAndrew 2016 - Forum software by © MyBB