开发者

Session variables can be fooled (login)?

开发者 https://www.devze.com 2022-12-23 02:26 出处:网络
IN PHP: Is there a way f开发者_如何学JAVAor the user to fake a session variable? Is it secure to trust in the value of a session variable for a login system?The session data is stored on the server.

IN PHP: Is there a way f开发者_如何学JAVAor the user to fake a session variable?

Is it secure to trust in the value of a session variable for a login system?


The session data is stored on the server. Only the session id is transferred forth and back between the client and the server. Unless a server-side script messes up (or there is a bug) the client cannot change the session data directly. But you have to ensure that only the "correct" client knows the session id, as it ties this particular client to a particular session. E.g. (since you mentioned a login) use session_regenerate_id() whenever a login (attempt) is performed to prevent session fixation


Sessions are stored on your server, either in a file or in memory. The user only holds a cookie that defines the path (usually a hash of some form) to the session data on your server. Theoretically you could change the cookie to someone else's hash, but that is very, very improbable, unless you store them as files and don't delete them after they expire, in which case the probability of someone exploiting an old session would increase.


Yes.. It's called session forge/hijack.

You change the value of the session cookie until you get another user session.


To avoid storing session data in the server, you can sign the content you want to protect from change, before storing it on session, and then validate just after retrieval from session. In PHP this process is reasonable simple and eliminates server storage issues.

Notice that this does not protect session data from being visualized. If you need this protection, you can still avoid server storage by using safe encryption. Just beware that virtually every encryption scheme based on key size can be broken on near future. So if you need to protect your session data for say, 5 years, the secure choice of key and algorithm might create performance issues.

0

精彩评论

暂无评论...
验证码 换一张
取 消