Jump to content


Photo

Is this a good security measure?


  • Please log in to reply
6 replies to this topic

#1 hadoob024

hadoob024
  • Members
  • PipPipPip
  • Advanced Member
  • 192 posts

Posted 09 March 2006 - 04:42 AM

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?

#2 beamerrox

beamerrox
  • Members
  • PipPipPip
  • Advanced Member
  • 35 posts
  • LocationGrimshaw, Alberta, Canada

Posted 09 March 2006 - 05:04 AM

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

#3 hadoob024

hadoob024
  • Members
  • PipPipPip
  • Advanced Member
  • 192 posts

Posted 09 March 2006 - 03:32 PM

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?

#4 lessthanthree

lessthanthree
  • Members
  • PipPipPip
  • Advanced Member
  • 85 posts
  • LocationUK

Posted 09 March 2006 - 03:38 PM

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.
call me a safe bet, i'm betting i'm not

#5 hadoob024

hadoob024
  • Members
  • PipPipPip
  • Advanced Member
  • 192 posts

Posted 09 March 2006 - 08:03 PM

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']?


#6 lessthanthree

lessthanthree
  • Members
  • PipPipPip
  • Advanced Member
  • 85 posts
  • LocationUK

Posted 09 March 2006 - 08:57 PM

[!--quoteo(post=353362:date=Mar 9 2006, 08:03 PM:name=hadoob024)--][div class=\'quotetop\']QUOTE(hadoob024 @ Mar 9 2006, 08:03 PM) View Post[/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.

call me a safe bet, i'm betting i'm not

#7 hadoob024

hadoob024
  • Members
  • PipPipPip
  • Advanced Member
  • 192 posts

Posted 10 March 2006 - 02:16 AM

Yeah. Basically, I'm using the following to clean my user inputs:

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;
}


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?





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users