Jump to content

How should I be filtering/validating these GET variables?


cgm225

Recommended Posts

I am using a php front controller, in which I GET two variables from the URL which are used to identify directory names, class filenames, and/or class names.  The code I am using is as such:

 

        $module= !empty($_GET["module"]) ? $_GET["module"] : "home";
        $action = !empty($_GET["action"]) ? $_GET["action"] : "frontpage";

 

However, I know I am never to trust external data passed to my script, so what type of filtering/validation should I be doing on these two GET variables?

 

Thanks in advance!

Link to comment
Share on other sites

directory names, shud go further down the directory root, so ya want to avoid '..'

 

which ya can check with realpath function

 

class names, if u know what to expect, store them in an array and do a comparison check, in_array function

Link to comment
Share on other sites

You probably want to avoid directory traversal attack so you should at least check if those values aren't "..", then probably something like is_dir(realpath($_GET['module'])). But if I'm not mistaken If you're using MVC pattern, then you can't use directory traversal attack because you're not pointing to directories but specific controllers.

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.