Jump to content

Is this a good security measure?


hadoob024

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.