Commit 9ec7d139 authored by Frédéric Buclin's avatar Frédéric Buclin

Bug 756550: Do not link a bug alias with its bug ID for bugs you cannot see

r=glob a=LpSolit
parent 17a866fd
...@@ -358,12 +358,14 @@ sub check { ...@@ -358,12 +358,14 @@ sub check {
# Bugzilla::Bug throws lots of special errors, so we don't call # Bugzilla::Bug throws lots of special errors, so we don't call
# SUPER::check, we just call our new and do our own checks. # SUPER::check, we just call our new and do our own checks.
my $self = $class->new(trim($id)); $id = trim($id);
my $self = $class->new($id);
if ($self->{error}) {
# For error messages, use the id that was returned by new(), because # For error messages, use the id that was returned by new(), because
# it's cleaned up. # it's cleaned up.
$id = $self->id; $id = $self->id;
if ($self->{error}) {
if ($self->{error} eq 'NotFound') { if ($self->{error} eq 'NotFound') {
ThrowUserError("bug_id_does_not_exist", { bug_id => $id }); ThrowUserError("bug_id_does_not_exist", { bug_id => $id });
} }
...@@ -375,7 +377,7 @@ sub check { ...@@ -375,7 +377,7 @@ sub check {
} }
unless ($field && $field =~ /^(dependson|blocked|dup_id)$/) { unless ($field && $field =~ /^(dependson|blocked|dup_id)$/) {
$self->check_is_visible; $self->check_is_visible($id);
} }
return $self; return $self;
} }
...@@ -391,16 +393,19 @@ sub check_for_edit { ...@@ -391,16 +393,19 @@ sub check_for_edit {
} }
sub check_is_visible { sub check_is_visible {
my $self = shift; my ($self, $input_id) = @_;
$input_id ||= $self->id;
my $user = Bugzilla->user; my $user = Bugzilla->user;
if (!$user->can_see_bug($self->id)) { if (!$user->can_see_bug($self->id)) {
# The error the user sees depends on whether or not they are # The error the user sees depends on whether or not they are
# logged in (i.e. $user->id contains the user's positive integer ID). # logged in (i.e. $user->id contains the user's positive integer ID).
# If we are validating an alias, then use it in the error message
# instead of its corresponding bug ID, to not disclose it.
if ($user->id) { if ($user->id) {
ThrowUserError("bug_access_denied", { bug_id => $self->id }); ThrowUserError("bug_access_denied", { bug_id => $input_id });
} else { } else {
ThrowUserError("bug_access_query", { bug_id => $self->id }); ThrowUserError("bug_access_query", { bug_id => $input_id });
} }
} }
} }
...@@ -1471,8 +1476,6 @@ sub _check_dependencies { ...@@ -1471,8 +1476,6 @@ sub _check_dependencies {
: split(/[\s,]+/, $deps_in{$type}); : split(/[\s,]+/, $deps_in{$type});
# Eliminate nulls. # Eliminate nulls.
@bug_ids = grep {$_} @bug_ids; @bug_ids = grep {$_} @bug_ids;
# We do this up here to make sure all aliases are converted to IDs.
@bug_ids = map { $invocant->check($_, $type)->id } @bug_ids;
my @check_access = @bug_ids; my @check_access = @bug_ids;
# When we're updating a bug, only added or removed bug_ids are # When we're updating a bug, only added or removed bug_ids are
...@@ -1503,7 +1506,8 @@ sub _check_dependencies { ...@@ -1503,7 +1506,8 @@ sub _check_dependencies {
} }
} }
} }
# Replace all aliases by their corresponding bug ID.
@bug_ids = map { $_ =~ /^(\d+)$/ ? $1 : $invocant->check($_, $type)->id } @bug_ids;
$deps_in{$type} = \@bug_ids; $deps_in{$type} = \@bug_ids;
} }
...@@ -1521,7 +1525,8 @@ sub _check_dup_id { ...@@ -1521,7 +1525,8 @@ sub _check_dup_id {
my ($self, $dupe_of) = @_; my ($self, $dupe_of) = @_;
my $dbh = Bugzilla->dbh; my $dbh = Bugzilla->dbh;
$dupe_of = trim($dupe_of); # Store the bug ID/alias passed by the user for visibility checks.
my $orig_dupe_of = $dupe_of = trim($dupe_of);
$dupe_of || ThrowCodeError('undefined_field', { field => 'dup_id' }); $dupe_of || ThrowCodeError('undefined_field', { field => 'dup_id' });
# Validate the bug ID. The second argument will force check() to only # Validate the bug ID. The second argument will force check() to only
# make sure that the bug exists, and convert the alias to the bug ID # make sure that the bug exists, and convert the alias to the bug ID
...@@ -1534,7 +1539,7 @@ sub _check_dup_id { ...@@ -1534,7 +1539,7 @@ sub _check_dup_id {
# If we come here, then the duplicate is new. We have to make sure # If we come here, then the duplicate is new. We have to make sure
# that we can view/change it (issue A on bug 96085). # that we can view/change it (issue A on bug 96085).
$dupe_of_bug->check_is_visible; $dupe_of_bug->check_is_visible($orig_dupe_of);
# Make sure a loop isn't created when marking this bug # Make sure a loop isn't created when marking this bug
# as duplicate. # as duplicate.
......
...@@ -285,9 +285,10 @@ sub _handle_alias { ...@@ -285,9 +285,10 @@ sub _handle_alias {
if ($searchstring =~ /^([^,\s]+)$/) { if ($searchstring =~ /^([^,\s]+)$/) {
my $alias = $1; my $alias = $1;
# We use this direct SQL because we want quicksearch to be VERY fast. # We use this direct SQL because we want quicksearch to be VERY fast.
my $is_alias = Bugzilla->dbh->selectrow_array( my $bug_id = Bugzilla->dbh->selectrow_array(
q{SELECT 1 FROM bugs WHERE alias = ?}, undef, $alias); q{SELECT bug_id FROM bugs WHERE alias = ?}, undef, $alias);
if ($is_alias) { # If the user cannot see the bug, do not resolve its alias.
if ($bug_id && Bugzilla->user->can_see_bug($bug_id)) {
$alias = url_quote($alias); $alias = url_quote($alias);
print Bugzilla->cgi->redirect( print Bugzilla->cgi->redirect(
-uri => correct_urlbase() . "show_bug.cgi?id=$alias"); -uri => correct_urlbase() . "show_bug.cgi?id=$alias");
......
...@@ -13,8 +13,7 @@ use lib qw(. lib); ...@@ -13,8 +13,7 @@ use lib qw(. lib);
use Bugzilla; use Bugzilla;
use Bugzilla::Constants; use Bugzilla::Constants;
use Bugzilla::Error; use Bugzilla::Error;
use Bugzilla::User; use Bugzilla::Util;
use Bugzilla::Keyword;
use Bugzilla::Bug; use Bugzilla::Bug;
my $cgi = Bugzilla->cgi; my $cgi = Bugzilla->cgi;
...@@ -38,7 +37,7 @@ if (!$cgi->param('id') && $single) { ...@@ -38,7 +37,7 @@ if (!$cgi->param('id') && $single) {
my $format = $template->get_format("bug/show", scalar $cgi->param('format'), my $format = $template->get_format("bug/show", scalar $cgi->param('format'),
scalar $cgi->param('ctype')); scalar $cgi->param('ctype'));
my @bugs; my (@bugs, @illegal_bugs);
my %marks; my %marks;
# If the user isn't logged in, we use data from the shadow DB. If he plans # If the user isn't logged in, we use data from the shadow DB. If he plans
...@@ -64,22 +63,23 @@ if ($single) { ...@@ -64,22 +63,23 @@ if ($single) {
foreach my $id ($cgi->param('id')) { foreach my $id ($cgi->param('id')) {
# Be kind enough and accept URLs of the form: id=1,2,3. # Be kind enough and accept URLs of the form: id=1,2,3.
my @ids = split(/,/, $id); my @ids = split(/,/, $id);
foreach (@ids) { foreach my $bug_id (@ids) {
my $bug = new Bugzilla::Bug($_); next unless $bug_id;
# This is basically a backwards-compatibility hack from when my $bug = new Bugzilla::Bug($bug_id);
# Bugzilla::Bug->new used to set 'NotPermitted' if you couldn't if (!$bug->{error} && $user->can_see_bug($bug->bug_id)) {
# see the bug.
if (!$bug->{error} && !$user->can_see_bug($bug->bug_id)) {
$bug->{error} = 'NotPermitted';
}
push(@bugs, $bug); push(@bugs, $bug);
} }
else {
push(@illegal_bugs, { bug_id => trim($bug_id),
error => $bug->{error} || 'NotPermitted' });
}
}
} }
} }
Bugzilla::Bug->preload(\@bugs); Bugzilla::Bug->preload(\@bugs);
$vars->{'bugs'} = \@bugs; $vars->{'bugs'} = [@bugs, @illegal_bugs];
$vars->{'marks'} = \%marks; $vars->{'marks'} = \%marks;
my @bugids = map {$_->bug_id} grep {!$_->error} @bugs; my @bugids = map {$_->bug_id} grep {!$_->error} @bugs;
......
...@@ -85,7 +85,8 @@ ...@@ -85,7 +85,8 @@
[% count = count + increment %] [% count = count + increment %]
[% END %] [% END %]
[% IF user.settings.comment_box_position.value == "before_comments" && user.id %] [% IF mode == "edit" && user.id
&& user.settings.comment_box_position.value == "before_comments" %]
<div class="bz_add_comment"> <div class="bz_add_comment">
<a href="#" <a href="#"
onclick="return goto_add_comments();"> onclick="return goto_add_comments();">
......
...@@ -77,9 +77,13 @@ ...@@ -77,9 +77,13 @@
[% ELSIF error == "alias_in_use" %] [% ELSIF error == "alias_in_use" %]
[% title = "Alias In Use" %] [% title = "Alias In Use" %]
[% IF user.can_see_bug(bug_id) %]
[% terms.Bug %] [%+ bug_id FILTER bug_link(bug_id) FILTER none %] [% terms.Bug %] [%+ bug_id FILTER bug_link(bug_id) FILTER none %]
[% ELSE %]
Another [% terms.bug %]
[% END %]
has already taken the alias <em>[% alias FILTER html %]</em>. has already taken the alias <em>[% alias FILTER html %]</em>.
Please choose another one. Please choose another alias.
[% ELSIF error == "alias_is_numeric" %] [% ELSIF error == "alias_is_numeric" %]
[% title = "Alias Is Numeric" %] [% title = "Alias Is Numeric" %]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment