Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web Apps: Storing ID in hidden fields safe?

I just had this thought, I don't know if I am slow though.

Usually, I store the id of the item I am editing in a hidden field. Then in backend (I am using PHP/Zend Framework btw), I get it to determine which item gets edited. But then I thought, in something more secure, eg. edit profile, the user can somehow edit a hidden field right? Then he can edit someone else's profile. I know for edit profile, I can get the id form the session variable, but what if i got something that requires me to store the id somewhere?

I got ACL (Zend_Acl) I do this. Basically grab the id from the request params

$id = $req->getParam('id');

then check if the logged in user is allowed to edit the item. But the thing is I wonder if the url is something like /users/edit/1 where 1 is the id. But somehow, the hidden field is changed to 2, what will the request param be?

How would you deal with this?

like image 478
Jiew Meng Avatar asked Aug 05 '10 12:08

Jiew Meng


2 Answers

You must store some kind of id at the client-otherwise how would you know which item to edit?
This does not free you from the mandatory check on the server that the current user has privileges to edit/see the edited item.
Other then that, why would you care how he got to edit the item (whether by lawful use of the web tool, or by editing the hidden/whatever field).

like image 124
Itay Moav -Malimovka Avatar answered Sep 28 '22 00:09

Itay Moav -Malimovka


Storing ID in hidden value isn't quite safe. Generally, we store ID in session variable.

like image 37
PPShein Avatar answered Sep 28 '22 00:09

PPShein