Jump to content

Archived

This topic is now archived and is closed to further replies.

hadoob024

Is this a good security measure?

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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']?

Share this post


Link to post
Share on other sites
[!--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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.