cgm225 Posted April 13, 2008 Share Posted April 13, 2008 I am using an MVC, am I the right filter on these GET variables, or should I be validating/filtering with a different filter/preg match? //The next two lines are ternary operators, a sort of short-hand for if-else $module= isset($_GET["module"]) ? filter_input(INPUT_GET, 'module', FILTER_SANITIZE_STRING) : "home"; $action = isset($_GET["action"]) ? filter_input(INPUT_GET, 'action', FILTER_SANITIZE_STRING) : "frontpage"; Link to comment https://forums.phpfreaks.com/topic/100937-i-am-using-an-mvc-am-i-the-right-filter-on-these-get-variables/ Share on other sites More sharing options...
cgm225 Posted April 14, 2008 Author Share Posted April 14, 2008 bump Link to comment https://forums.phpfreaks.com/topic/100937-i-am-using-an-mvc-am-i-the-right-filter-on-these-get-variables/#findComment-516417 Share on other sites More sharing options...
discomatt Posted April 14, 2008 Share Posted April 14, 2008 Personally, I would attempt to match them them within an array of installed modules or actions. Link to comment https://forums.phpfreaks.com/topic/100937-i-am-using-an-mvc-am-i-the-right-filter-on-these-get-variables/#findComment-516432 Share on other sites More sharing options...
cgm225 Posted April 14, 2008 Author Share Posted April 14, 2008 What if I don't have a list of installed modules. Are these filters the right way to go? Link to comment https://forums.phpfreaks.com/topic/100937-i-am-using-an-mvc-am-i-the-right-filter-on-these-get-variables/#findComment-516867 Share on other sites More sharing options...
discomatt Posted April 14, 2008 Share Posted April 14, 2008 Well, there's no gaurantee they're not trying to access a module they don't have access to... or one they shouldn't be looking at. But as far as stripping unwanted characters and preventing injection... it seems fine. Personally, I'd use a regex function with a white list of allowed characters... gives you a little more control. This code strips anything that isn't a letter, number, underscore or hyphen $regex = '/[^-_A-z0-9]++/'; $module = preg_replace($regex, '', $_GET['module']); $action = preg_replace($regex, '', $_GET['action']); Or you can fail completely on an injection attempt $regex = '/[^-_A-z0-9]/'; if ( preg_match($regex, $_GET['module']) || preg_match($regex, $_GET['action']) ) { // injection attempt detected exit('Invalid input variables detected'); } Link to comment https://forums.phpfreaks.com/topic/100937-i-am-using-an-mvc-am-i-the-right-filter-on-these-get-variables/#findComment-516889 Share on other sites More sharing options...
cgm225 Posted April 14, 2008 Author Share Posted April 14, 2008 Thank you! Link to comment https://forums.phpfreaks.com/topic/100937-i-am-using-an-mvc-am-i-the-right-filter-on-these-get-variables/#findComment-517000 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.