views:

56

answers:

4

I want to check the user whether they have sign in or not, so I assign a hidden from field to store the session key, and I have a post method form to submit.

Can others/hackers, copy my session key from my field and send a post method to the server?? If yes, how can I do to avoid this?

+1  A: 

Can others/hackers, copy my session key from my field and send a post method to the server??

Yes.

If you want to minimize the risk of credentials leaking, use encryption (SSL (HTTPS)).

David Dorward
that will not protect him from someone with access to the local machine. But it's the obvious first step to take, I agree, so +1
lexu
If someone has access to the local machine, then there is no security at all.
David Dorward
A: 

Yes, copying and resending the key from somewhere else can be easily done.

The trick is to make certain the session key is only valid for a limited time and can not easily be deduced from other data in the form.

You might e.g. use a good encryption method to encode username, IP address and time into a session key. Decoding that key would allow you to verify user, system and time .. not entirely fool proof still ...

This will limit but not eliminate the risk

lexu
A: 

You should use a serverside language to check the session key. It'll be much safer.

There are a couple of problems with having it as a hidden value. 1) The user could save the form, then change the value and try to hijack another session 2) You could have a man in the middle situation where someones listening for the form to be submitted and then hijack there session...

silent1mezzo
Nobody is suggesting using anything other than a server side language to check the key. (1) Users can **always** try to guess another session key, no matter where you store it. (2) Yes, but where the key is stored doesn't matter for that, only how it is transmitted.
David Dorward
A: 

You can use hashes and timestampes which is discussed here, but most web development frameworks provide some sort of built-in authentication mechanisms.

tarn