Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Can a client ever set $_SESSION variables?

Tags:

Is there any scenario where a client/user/hacker can set $_SESSION variables themselves (excluding malicious software running on a server computer. I mostly mean via the browser)?

The reason I ask is because of this question that I asked a few days ago. Since then I have become pretty confused on the subject, but I've got a better idea of session fixation and hijacking.

To put it as simply as possible, if I validate every page with something like isset($_SESSION['validated']), is it secure?

like image 698
Ben Avatar asked Nov 15 '10 06:11

Ben


People also ask

Can the client access session variables?

Session variables can be accessed on the client side. For example you could check the value by calling: alert('<%=Session["RegisterId"] %>'); Anything between the "<%" and "%>" runs at the server so it will evaluate the current value of the session.

Can client change session variables?

@George Korac: Yes.

What is the purpose of $_ session variable in PHP?

PHP $_SESSION is an associative array that contains all session variables. It is used to set and get session variable values.

Is $_ session a global variable?

Session variables are set with the PHP global variable: $_SESSION.


2 Answers

Yes if you were assigning $_SESSION variables directly to unfiltered user input.

Which brings me to my point: NEVER TRUST INPUT FROM THE USER. EVER

If indeed you are filtering the input, then I don't see how it could be done.

like image 135
Jacob Relkin Avatar answered Sep 20 '22 18:09

Jacob Relkin


Yes, it's possible. Read about Session poisoning and another quite common security issue Session fixation on Wikipedia or Google it - the web is full of articles about that.

like image 40
Crozin Avatar answered Sep 24 '22 18:09

Crozin