Hi guys.
I'm trying to improve my site secuity, and I'm stumped on what to do in this case.
We have a ticket system, and allow users (there is no membership, so we only check it's their ticket if they provide the correct ID, password and a password that's stored in the ticket database) to reply to their tickets.
I'm using the following code, but also have a hidden field for id_ticket:
<input type=\"hidden\" name=\"id\" value=\"".$myrow['id_ticket']."\" />
To stop multiple submissions on refreshed data etc, I have:
In the reply page:
$secret=md5(uniqid(rand(), true));
$_SESSION['REPLY_FORM_SECRET']=$secret;
echo it with:
echo " <input type=\"hidden\" name=\"reply_form_secret\" id=\"reply_form_secret\" value=\"".$_SESSION['REPLY_FORM_SECRET']."\" />\n";
--------------------------
in the process.php:
// Retrieve the value of the hidden field
$form_secret = htmlentities($_POST['form_secret']);
if(isset($_SESSION['FORM_SECRET'])) {
if(strcasecmp($form_secret,$_SESSION['FORM_SECRET'])===0) {
// valid
unset($_SESSION['FORM_SECRET']);
} else {
echo "<ul>\n<li><span>Invalid code</span></li>\n</ul>\n\n";
echo "<p class=\"righttext\"><small>Go back to <strong><a href=\"javascript:history.go(-1)\" title=\"previous page\">previous page</a></strong></small></p>\n\n";
}
} else {
echo "<ul>\n<li><span>Invalid code</span></li>\n</ul>\n\n";
echo "<p class=\"righttext\"><small>Go back to <strong><a href=\"javascript:history.go(-1)\" title=\"previous page\">previous page</a></strong></small></p>\n\n";
}
The problem: I am concerned as I realise that the user could easily alter the id_ticket, and then their reply would be processed and alter another ticket...
Is there a way I can modify the above code I currenty use to stop multiple submissions to secure this? By maybe having it purely in $_SESSION to check a code (that would fix the hidden id_ticket possible problem too...)
One other problem I have that code, is if someone opens two windows to a page, then it invalidates one. I don't know a a workaround for that either...
Any help appreciated 🙂