So how do you maintain the form security ? For instance you have a member and he/she tries to change the personal settings and you redirected member to
Well, in your example, your URL would actually be /member/change . The ID you require would come from the current users ‘session’, so would be impossible to change.
If however, the current user is actually an admin, the ID would indeed need to be specified but they would have the right to alter any user anyway.7
Additionally, if you require a more fine-grained mechanism, you could look into ACLs.
As with the session solution I reread my question and found out what I miss.
For instance the user has unlimited number of sub pages and again user want to change the content of that page, without using session (by session I mean, saving the page id to session) how can I achieve to protect another page to be changed ?
Actually I am looking for an independent security approach like I put a hashed string to a hidden and try to check that but I dont wthat hash dependent on things that can be guessed.
In which case, you need to generate a hash which is reproduciable on a subsequent request but unique to both the current user and relevant ‘page’.
$hash = sha1(
sprintf(
'%d-%s-%s-%s',
$this->user->get('id'), #users id
$this->user->get('browser'), #users browser
$this->page->get('slug'), #unique element for page /members/edit/4 for example
$this->config->get('security.key') #a secret key known only to the application
)
);
This is actually what I was looking for thank you very much Anthony and also to you felgall. By this hashing method we can generalize the checking mechanism and create a generic security tool.
You can generate the hash from user info as Anthony suggests or you could generate a random hash and then store it in the database with the user data and then compare the one from the session data against the one stored directly in the database rather than rebuilding the hash based on the info in the database.