hadoob024 Posted March 9, 2006 Share Posted March 9, 2006 This isn't all the security checking that I'm doing, but I thought that it might be useful. Let me know what everyone thinks.I was thinking of creating an array that contains all of the PHP pages that I have (well, the ones accessible by the browser and not just includes and such). And then at the beginning of every file, I wanted to check and see whether or not we came from one of the files listed in the array. If not, then do a re-direct on them to index.php or something similar to this. And I was thinking of checking the values by accessing the values stored in something like $_SERVER['HTTP_REFERER'] or maybe $_SERVER['REQUEST_URI'].Also, more specifically, if someone tries to access a page that processes a form, I want to check and make sure that they only got to that page by accessing the page that contains the actual form. If not, re-direct them to the page with the form on it.So, any thoughts on this? Quote Link to comment Share on other sites More sharing options...
beamerrox Posted March 9, 2006 Share Posted March 9, 2006 if someone wants to submit a form to your website from someplace else, why not let him...unless he is trying to hack ur site, he is most likely spamming or posting usefull information, just like normal users Quote Link to comment Share on other sites More sharing options...
hadoob024 Posted March 9, 2006 Author Share Posted March 9, 2006 But I thought that you ALWAYS want to make sure that the form is being submitted from your site? It seems like there aren't that many benefits to being able to submit a form, and not doing so from my site. And it seems if they can submit from anywhere, that there would be a lot more probable security issues, so that I shouldn't allow it. Am I right, or just being paranoid? Quote Link to comment Share on other sites More sharing options...
lessthanthree Posted March 9, 2006 Share Posted March 9, 2006 For security's sake, you SHOULD indeed do your utmost to make sure the form is being submitted to your site FROM your site. There is no true reason for someone to be creating their own form and submitting it to your form handler. Quote Link to comment Share on other sites More sharing options...
hadoob024 Posted March 9, 2006 Author Share Posted March 9, 2006 So, then in addition to adding the session token functionality, would it be helpful to add the functionality that if someone tries to access a page that processes a form, I want to check and make sure that they only got to that page by accessing the page that contains the actual form? And if not, re-direct them to the page with the form on it? And that I could do this by accessing the value from $_SERVER['REQUEST_URI']? Quote Link to comment Share on other sites More sharing options...
lessthanthree Posted March 9, 2006 Share Posted March 9, 2006 [!--quoteo(post=353362:date=Mar 9 2006, 08:03 PM:name=hadoob024)--][div class=\'quotetop\']QUOTE(hadoob024 @ Mar 9 2006, 08:03 PM) [snapback]353362[/snapback][/div][div class=\'quotemain\'][!--quotec--]So, then in addition to adding the session token functionality, would it be helpful to add the functionality that if someone tries to access a page that processes a form, I want to check and make sure that they only got to that page by accessing the page that contains the actual form? And if not, re-direct them to the page with the form on it? And that I could do this by accessing the value from $_SERVER['REQUEST_URI']?[/quote]You can try and stop them from submitting it from a different location using the above....however it's most likely still going to be possible to get around it. Therefore whatever you do, make doubly sure you have cleaned and validated the inputs as much as possible on your form handler before doing any kind of database query with the data. Quote Link to comment Share on other sites More sharing options...
hadoob024 Posted March 10, 2006 Author Share Posted March 10, 2006 Yeah. Basically, I'm using the following to clean my user inputs:[code]function cleanit($cleanedvar){ $badchars = array(';', '&', '|', '<', '>', '=', '/', '\\'); if (get_magic_quotes_gpc()) { $cleanedvar = stripslashes($cleanedvar); } $cleanedvar = trim($cleanedvar); $cleanedvar = strip_tags($cleanedvar); $cleanedvar = str_replace($badchars, '', $cleanedvar); if ((is_numeric($cleanedvar)) && ((intval($cleanedvar) == floatval($cleanedvar)))) return (intval($cleanedvar)); elseif ((is_numeric($cleanedvar)) && ((intval($cleanedvar) != floatval($cleanedvar)))) return (floatval($cleanedvar)); else return $cleanedvar;}[/code]And then after calling this function, I go back and check each of the inputted variables using eregi(), and then eventually use mysql_real_escape_string() before creating the SQL search string. Any suggestions on top of this?So what does everyone do to make sure that a user can't directly access a page that processes a form, and instead has to access the form page directly? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.