Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web: remove XSS vulnerability. #5149

Merged
merged 1 commit into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions html/inc/util.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,20 @@ function sanitize_email($x) {
}
}

// pages like top_hosts.php, team_members.php etc. have a textual
// "sort_by" argument.
// Check this to avoid XSS vulnerability
//
function sanitize_sort_by($x) {
switch($x) {
case 'expavg_credit':
case 'total_credit':
return;
default:
error_page('bad sort_by');
}
}

function flops_to_credit($f) {
return $f*(200/86400e9);
}
Expand Down
6 changes: 3 additions & 3 deletions html/user/team_members.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@

check_get_args(array("sort_by", "offset", "teamid"));

if (isset($_GET["sort_by"])) {
$sort_by = $_GET["sort_by"];
$sort_by = strip_tags($sort_by); // remove XSS nonsense
$sort_by = get_str("sort_by", true);
if ($sort_by) {
sanitize_sort_by($sort_by);
} else {
$sort_by = "expavg_credit";
}
Expand Down
12 changes: 5 additions & 7 deletions html/user/top_hosts.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,11 @@ function get_top_hosts($offset, $sort_by) {
return BoincHost::enum(null, "order by $sort_order limit $offset, $hosts_per_page");
}

$sort_by = get_str("sort_by", true);
switch ($sort_by) {
case "total_credit":
case "expavg_credit":
break;
default:
$sort_by = "expavg_credit";
$sort_by = get_str('sort_by', true);
if ($sort_by) {
sanitize_sort_by($sort_by);
} else {
$sort_by = 'expavg_credit';
}

$offset = get_int("offset", true);
Expand Down
12 changes: 5 additions & 7 deletions html/user/top_teams.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,11 @@ function get_top_teams($offset, $sort_by, $type){
return BoincTeam::enum($type_clause, "order by $sort_order limit $offset, $teams_per_page");
}

$sort_by = get_str("sort_by", true);
switch ($sort_by) {
case "total_credit":
case "expavg_credit":
break;
default:
$sort_by = "expavg_credit";
$sort_by = get_str('sort_by', true);
if ($sort_by) {
sanitize_sort_by($sort_by);
} else {
$sort_by = 'expavg_credit';
}

$type = get_int("type", true);
Expand Down
12 changes: 5 additions & 7 deletions html/user/top_users.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,11 @@ function show_user_row($user, $i) {
";
}

$sort_by = get_str("sort_by", true);
switch ($sort_by) {
case "total_credit":
case "expavg_credit":
break;
default:
$sort_by = "expavg_credit";
$sort_by = get_str('sort_by', true);
if ($sort_by) {
sanitize_sort_by($sort_by);
} else {
$sort_by = 'expavg_credit';
}

$offset = get_int("offset", true);
Expand Down