I have a script which gathers information from the users, validates it and sends it onwards to insert into a DB.
To avoid any nasty problems on each of the form fields I run always an "htmlspecialchars" and "addslashes".
Today I look in my error log and found the following error:
Unknown: open(/tmp/sess_574af1197644f6c4019d664d71ea5f9e, O_RDWR) failed: Permission denied (13)
This error is being generated in the file that process the form. Apparently, somebody try to 'hack' into my application. What I'm struggling with is how to prevent this. Luckily my server access level was setup in the correct way, but otherwise we would have an issue.
How/what do I need to change on my form validation to capture these kind of hacks on the front end and not at the server access level?
<?php
session_start();
include ($_SERVER['DOCUMENT_ROOT'].'/inc/config.inc.php');
if ($_POST[leverancier]) { $lid = CheckNumericGet($_POST[leverancier]); }
// Afhandelen van de submit
//
if ($_POST[a] == 'ervaring') {
$naam = CheckStringGet($_POST[naam]);
$ervaring = CheckStringGet($_POST[ervaring]);
$email = CheckStringGet($_POST[email]);
$twitter_naam = CheckStringGet($_POST[twitter_naam]);
// Als er een @ in twitternaam zit weghalen
//
if (substr($twitter_naam, 0,1) == '@') {
$twitter_naam = substr($twitter_naam, 1);
}
include ($_SERVER['DOCUMENT_ROOT'].'/inc/functies_mail.inc.php');
$cont = "yes";
if ($naam == '' | $ervaring == '' | $email == '' | $rating_foto == '' | $rating_service == '' | $besteld == 0) {
$cont = "no";
$msg[][1] = "Helaas, niet alle verplichte velden zijn ingevuld. Probeer het nogmaals.";
}
if (!CheckEmail($email)) {
$cont = "no";
$msg[][1] = "Het ingevulde email adres is niet correct";
}
#Als alle velden ingevuld zijn
if ($cont == 'yes') {
$server = gethostbyaddr($_SERVER['REMOTE_ADDR']);
// Ervaring in database plaatsen
//
$query = "INSERT INTO
". $tabel_ervaring ." (lid, naam, email, foto_score, service_score, ervaring, datum, foto, canvas, album, actief, twitter_naam, lev_akkoord)
VALUES
($lid, '$naam', '$email', $rating_foto, $rating_service, '$ervaring', '$datum', '$foto', '$canvas', '$album', '0', '$twitter_naam', '$akkoord')";
$result = mysql_query($query) or die(mysql_fout($query, $PHP_SELF));
$ervaring_id = mysql_insert_id();
$message = "";
$subject = "Ervaring Fotovergelijk.nl: ";
mail("xxx@xxx", "$subject", $message, htmlemailheaders($email));
}
$_SESSION[message] = $msg;
}