I recently had a chat with a cracker and he told me that he can get past uri regexp checking.
I'm checking if the path_info matches my regexp and after that I match that to my routing table. If there is no routing for that path i redirect to a 404 page.
I have some little code here and I was wondering whehter someone can crack this by providing wrong data or my web app is protected? Is it possible to bypass this? (Please note that this is just some sample code):
<?php
// alphabetic characters, numbers, "-" and "/" are allowed
$pathRegex = '/[a-zA-Z0-9\/-]+/';
$pathInfo = $_SERVER["PATH_INFO"];
$routes = array(
"homepage" => "/",
"some_page" => "/param1/param2-something"
);
$res = preg_match($pathRegex, $pathInfo, $matches);
if ($res && $matches[0] == $pathInfo) {
if (checkRouting($pathInfo, $routes)) {
// keep on running
} else {
// 404, sorry
}
} else {
// wrong path
}
function checkRouting($path, $routes) {
$res = false;
foreach($routes as $key => $val) {
if ($val == $path) {
$res = true;
break;
}
}
return $res;
}
?>