Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is storing data in PHP $_SESSION insecure?

As per my understanding, PHP processes doesn't behave as application server process. So, after the execution of a script the PHP process retains no user specific data. It instead stores them in the user's cookie. So whatever we store in $_SESSSION goes into cookies. Is this true? If yes then are they stored in clear text or some encoding or encryption is done?

like image 555
AppleGrew Avatar asked Aug 15 '11 20:08

AppleGrew


People also ask

Is PHP $_ session secure?

“Is a PHP session secure? PHP sessions are only as secure as your application makes them. PHP sessions will allow the client a pseudorandom string (“session ID”) for them to distinguish themselves with, but on the off chance that the string is intercepted by an attacker, the aggressor can imagine to be that client.

Is it safe to store in session?

Both SessionStorage and LocalStorage are vulnerable to XSS attacks. Therefore avoid storing sensitive data in browser storage. It's recommended to use the browser storage when there is, No sensitive data.

Can PHP session data be hacked?

No. Session data is stored on the server. The session ID is the only thing transferred back and forward between the client and the server.

Are session variables secure?

By default, session variables are created with the secure flag set to true. If any secure variables are saved to the database, you must type your password, which is used as the encryption key.


2 Answers

No, the only thing that goes into the session cookie is the ID of the session - a random alphanumeric string. All the session data is stored on the server in a file (using the default session handler, though you can override to store the data anywhere/any way you want).

like image 58
Marc B Avatar answered Oct 30 '22 12:10

Marc B


No, that is not true. Only the session's ID is stored in the session cookie. The session data is all stored server-side (albeit in plain text, by default).

like image 25
ceejayoz Avatar answered Oct 30 '22 11:10

ceejayoz