MDL-17799 proper log url sanitisation - big thanks to Full Name hacker ;-) backported from HEAD

This commit is contained in:
skodak
2009-01-07 23:02:56 +00:00
parent 0260923ace
commit e15c4f35c4
+35 -8
View File
@@ -246,19 +246,50 @@ function make_log_url($module, $url) {
case 'message':
case 'calendar':
case 'blog':
return "/$module/$url";
if (strpos($url, '../') === 0) {
$url = ltrim($url, '.');
} else {
$url = "/course/$url";
}
break;
$url = "/$module/$url";
break;
case 'upload':
return $url;
$url = $url;
break;
case 'library':
case '':
return '/';
$url = '/';
break;
default:
return "/mod/$module/$url";
$url = "/mod/$module/$url";
break;
}
//now let's sanitise urls - there might be some ugly nasties:-(
$parts = explode('?', $url);
$script = array_shift($parts);
if (strpos($script, 'http') === 0) {
$script = clean_param($script, PARAM_URL);
} else {
$script = clean_param($script, PARAM_PATH);
}
$query = '';
if ($parts) {
$query = implode('', $parts);
$query = str_replace('&', '&', $query); // both & and & are stored in db :-|
$parts = explode('&', $query);
$eq = urlencode('=');
foreach ($parts as $key=>$part) {
$part = urlencode(urldecode($part));
$part = str_replace($eq, '=', $part);
$parts[$key] = $part;
}
$query = '?'.implode('&', $parts);
}
return $script.$query;
}
function print_log($course, $user=0, $date=0, $order="l.time ASC", $page=0, $perpage=100,
@@ -406,10 +437,6 @@ function print_log($course, $user=0, $date=0, $order="l.time ASC", $page=0, $per
//Filter log->info
$log->info = format_string($log->info);
$log->url = strip_tags(urldecode($log->url)); // Some XSS protection
$log->info = strip_tags(urldecode($log->info)); // Some XSS protection
$log->url = s($log->url); /// XSS protection and XHTML compatibility - should be in link_to_popup_window() instead!!
echo '<tr class="r'.$row.'">';
if ($course->id == SITEID) {
echo "<td class=\"r$row c0\" nowrap=\"nowrap\">\n";