From: lpsolit%gmail.com <> Date: Mon, 2 Feb 2009 18:48:38 +0000 (+0000) Subject: Bug 466748: [SECURITY] Shared/saved searches can be deleted without user confirmation... X-Git-Tag: bugzilla-3.3.2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=44341577cd209d8c61fe4129ea72785fc7be9ee5;p=thirdparty%2Fbugzilla.git Bug 466748: [SECURITY] Shared/saved searches can be deleted without user confirmation using predictable URL - Patch by Frédéric Buclin r=mkanat a=LpSolit --- diff --git a/buglist.cgi b/buglist.cgi index f5284439c1..de7e56bd7e 100755 --- a/buglist.cgi +++ b/buglist.cgi @@ -290,7 +290,7 @@ sub LookupNamedQuery { $result || ThrowUserError("buglist_parameters_required", {'queryname' => $name}); - return $result; + return wantarray ? ($result, $id) : $result; } # Inserts a Named Query (a "Saved Search") into the database, or @@ -448,14 +448,16 @@ $filename =~ s/"/\\"/g; # escape quotes # Take appropriate action based on user's request. if ($cgi->param('cmdtype') eq "dorem") { if ($cgi->param('remaction') eq "run") { - $buffer = LookupNamedQuery(scalar $cgi->param("namedcmd"), - scalar $cgi->param('sharer_id')); + my $query_id; + ($buffer, $query_id) = LookupNamedQuery(scalar $cgi->param("namedcmd"), + scalar $cgi->param('sharer_id')); # If this is the user's own query, remember information about it # so that it can be modified easily. $vars->{'searchname'} = $cgi->param('namedcmd'); if (!$cgi->param('sharer_id') || $cgi->param('sharer_id') == Bugzilla->user->id) { $vars->{'searchtype'} = "saved"; + $vars->{'search_id'} = $query_id; } $params = new Bugzilla::CGI($buffer); $order = $params->param('order') || $order; @@ -504,6 +506,10 @@ if ($cgi->param('cmdtype') eq "dorem") { # The user has no query of this name. Play along. } else { + # Make sure the user really wants to delete his saved search. + my $token = $cgi->param('token'); + check_hash_token($token, [$query_id, $qname]); + $dbh->do('DELETE FROM namedqueries WHERE id = ?', undef, $query_id); @@ -557,9 +563,12 @@ elsif (($cgi->param('cmdtype') eq "doit") && defined $cgi->param('remtype')) { my %bug_ids; my $is_new_name = 0; if ($query_name) { + my ($query, $query_id) = + LookupNamedQuery($query_name, undef, QUERY_LIST, !THROW_ERROR); # Make sure this name is not already in use by a normal saved search. - if (LookupNamedQuery($query_name, undef, QUERY_LIST, !THROW_ERROR)) { - ThrowUserError('query_name_exists', {'name' => $query_name}); + if ($query) { + ThrowUserError('query_name_exists', {name => $query_name, + query_id => $query_id}); } $is_new_name = 1; } diff --git a/template/en/default/account/prefs/saved-searches.html.tmpl b/template/en/default/account/prefs/saved-searches.html.tmpl index 709cf49c5f..280b932ba8 100644 --- a/template/en/default/account/prefs/saved-searches.html.tmpl +++ b/template/en/default/account/prefs/saved-searches.html.tmpl @@ -108,7 +108,8 @@ Remove from whining first [% ELSE %] Forget + [% q.name FILTER url_quote %]&token= + [% issue_hash_token([q.id, q.name]) FILTER url_quote %]">Forget [% END %] diff --git a/template/en/default/global/user-error.html.tmpl b/template/en/default/global/user-error.html.tmpl index 0606857dd7..1efee9a5e5 100644 --- a/template/en/default/global/user-error.html.tmpl +++ b/template/en/default/global/user-error.html.tmpl @@ -1391,8 +1391,9 @@ The name [% name FILTER html %] is already used by another saved search. You first have to delete it if you really want to use - this name. + [%- name FILTER url_quote %]&token= + [% issue_hash_token([query_id, name]) FILTER url_quote %]">delete + it if you really want to use this name. [% ELSIF error == "query_name_missing" %] [% title = "No Search Name Specified" %] diff --git a/template/en/default/list/list.html.tmpl b/template/en/default/list/list.html.tmpl index 4929c416d0..a75f1340cf 100644 --- a/template/en/default/list/list.html.tmpl +++ b/template/en/default/list/list.html.tmpl @@ -228,8 +228,9 @@ | Forget Search ' - [% searchname FILTER html %]' + [% searchname FILTER url_quote %]&token= + [% issue_hash_token([search_id, searchname]) FILTER url_quote %]"> + Forget Search '[% searchname FILTER html %]' [% ELSE %]