Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
a22b712
Bug 2094122 - Migrate the InvalidBugHelper REST resource to native Mo…
Xzzz Nov 17, 2026
01f3262
Bug 2094122 - Migrate the Bitly REST resource to native Mojo API
Xzzz Nov 17, 2026
1dfb750
Bug 2094122 - Migrate the ProdCompSearch REST resource to native Mojo…
Xzzz Nov 17, 2026
d8b9ef1
Bug 2094122 - Migrate the EditComments REST resource to native Mojo API
Xzzz Nov 17, 2026
7d7e6fd
Bug 2094122 - Migrate the ComponentWatching REST resource to native M…
Xzzz Nov 18, 2026
639f232
Bug 2094122 - Migrate the MyDashboard REST resource to native Mojo API
Xzzz Nov 18, 2026
3686a95
Bug 2094122 - Fix - Refuse an unknown type in MyDashboard run_flag_query
Xzzz Nov 18, 2026
45a6fab
Bug 2094122 - Migrate the PhabBugz REST resource to native Mojo API
Xzzz Nov 18, 2026
4af97f4
Bug 2094122 - Migrate the Review REST resource to native Mojo API
Xzzz Nov 18, 2026
bab1d8b
Bug 2094122 - Migrate the BugModal REST resource to native Mojo API
Xzzz Nov 18, 2026
e3b983a
Bug 2094122 - Fix - Keep the path id on BugModal GET routes
Xzzz Nov 18, 2026
7c98353
Bug 2094122 - Fix - Answer an empty ProdCompSearch search with param_…
Xzzz Nov 18, 2026
250add2
Bug 2094122 - Fix - Accept an empty value in Review flag_activity paths
Xzzz Nov 18, 2026
904f10f
Bug 2094122 - Fix - Read the EditComments comment ID from the path only
Xzzz Nov 19, 2026
c2fc050
Bug 2094122 - Test - Refuse PhabBugz bug_revisions on a bug the user …
Xzzz Nov 19, 2026
923ab55
Bug 2094122 - Test - Cover private comments and hidden bugs in the Ed…
Xzzz Nov 19, 2026
e30e77d
Bug 2094122 - Test - Cover hidden bugs and non-taggers in the BugModa…
Xzzz Nov 19, 2026
6d0c336
Bug 2094122 - Test - Cover private comments and hidden bugs in MyDash…
Xzzz Nov 19, 2026
ac8a508
Bug 2094122 - Test - Refuse InvalidBugHelper close for non-editbugs c…
Xzzz Nov 19, 2026
383001e
Bug 2094122 - Answer the CORS preflight on the migrated extension routes
Xzzz Nov 20, 2026
d80acb4
Bug 2094122 - Check PhabBugz permissions on the main database
Xzzz Nov 20, 2026
a1974c7
Bug 2094122 - Refuse arrays and hashes where a boolean is expected
Xzzz Nov 20, 2026
234ed34
Bug 2094122 - Fix - Accept a single JSON value for a list param
Xzzz Nov 20, 2026
3f6860d
Bug 2094122 - Fix - Match every bug_id and status given to flag_activity
Xzzz Nov 20, 2026
4b568e6
Bug 2094122 - Fix - Refuse a hash or a nested list for a list param
Xzzz Nov 20, 2026
7d78dcb
Bug 2094122 - Fix - Keep every include_fields/exclude_fields value gi…
Xzzz Nov 23, 2026
18f36e3
Bug 2094122 - Fix - Drop the legacy credentials caveat from the API docs
Xzzz Nov 23, 2026
a92f925
Bug 2094122 - Fix - Return the list param error from merge_request_pa…
Xzzz Nov 24, 2026
c7fa096
Merge branch 'master' into bug-2094122
dklawren Nov 24, 2026
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
12 changes: 6 additions & 6 deletions Bugzilla/API/V1/BugAttachment.pm
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ sub add_attachment {
my $user = $self->bugzilla->login;
$user->id || return $self->user_error('login_required');

my ($params, $error) = $self->_request_params;
return $self->user_error($error) if $error;
my ($params, $error, $vars) = $self->_request_params;
return $self->user_error($error, $vars) if $error;

defined $params->{data}
|| return $self->code_error('param_required', {param => 'data'});
Expand Down Expand Up @@ -231,8 +231,8 @@ sub update_attachment {
my $user = $self->bugzilla->login;
$user->id || return $self->user_error('login_required');

my ($params, $error) = $self->_request_params;
return $self->user_error($error) if $error;
my ($params, $error, $vars) = $self->_request_params;
return $self->user_error($error, $vars) if $error;

my $dbh = Bugzilla->dbh;
my $ids = delete $params->{ids};
Expand Down Expand Up @@ -369,9 +369,9 @@ sub update_attachment {
sub _request_params {
my ($self) = @_;

my ($params, $error)
my ($params, $error, $vars)
= merge_request_params($self, [qw(ids include_fields exclude_fields)]);
return (undef, $error) if $error;
return (undef, $error, $vars) if $error;

# As legacy validate(@_, 'ids'): a single id becomes a list, and anything
# but a list of plain values (e.g. a hash of conditions) is invalid_params.
Expand Down
4 changes: 2 additions & 2 deletions Bugzilla/API/V1/BugComment.pm
Original file line number Diff line number Diff line change
Expand Up @@ -409,9 +409,9 @@ sub search_comment_tags {
sub _request_params {
my ($self) = @_;

my ($params, $error)
my ($params, $error, $vars)
= merge_request_params($self, [qw(add remove comment_tags)]);
return (undef, $error) if $error;
return (undef, $error, $vars) if $error;

$params->{$_} //= $self->stash($_) for qw(id comment_id);

Expand Down
12 changes: 6 additions & 6 deletions Bugzilla/API/V1/BugUserLastVisit.pm
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ sub get {
my $user = $self->bugzilla->login;
$user->id || return $self->user_error('login_required');

my ($params, $params_error) = $self->_request_params;
return $self->user_error($params_error) if $params_error;
my ($params, $params_error, $params_vars) = $self->_request_params;
return $self->user_error($params_error, $params_vars) if $params_error;

my ($ids, $error, $vars) = $self->_ids_from_request($params);
return $self->user_error($error, $vars) if $error;
Expand Down Expand Up @@ -82,8 +82,8 @@ sub update {
my $user = $self->bugzilla->login;
$user->id || return $self->user_error('login_required');

my ($params, $params_error) = $self->_request_params;
return $self->user_error($params_error) if $params_error;
my ($params, $params_error, $params_vars) = $self->_request_params;
return $self->user_error($params_error, $params_vars) if $params_error;

my ($ids, $error, $vars) = $self->_ids_from_request($params);
return $self->user_error($error, $vars) if $error;
Expand Down Expand Up @@ -141,8 +141,8 @@ sub _ids_from_request {
sub _request_params {
my ($self) = @_;

my ($params, $error) = merge_request_params($self, ['ids']);
return (undef, $error) if $error;
my ($params, $error, $vars) = merge_request_params($self, ['ids']);
return (undef, $error, $vars) if $error;

for my $field (qw(include_fields exclude_fields)) {
$params->{$field} = [split(/[\s,]+/, $params->{$field})]
Expand Down
8 changes: 4 additions & 4 deletions Bugzilla/API/V1/Group.pm
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ sub update {
|| return $self->user_error('auth_failure',
{group => 'creategroups', action => 'edit', object => 'groups'});

my ($params, $error) = merge_request_params($self, ['ids', 'names']);
return $self->user_error($error) if $error;
my ($params, $error, $vars) = merge_request_params($self, ['ids', 'names']);
return $self->user_error($error, $vars) if $error;

my $type_error = coerce_booleans($params, 'is_active');
return $self->user_error('invalid_params', {type_error => $type_error})
Expand Down Expand Up @@ -147,8 +147,8 @@ sub get {
my $user = $self->bugzilla->login;
$user->id || return $self->user_error('login_required');

my ($params, $error) = merge_request_params($self, ['ids', 'names']);
return $self->user_error($error) if $error;
my ($params, $error, $vars) = merge_request_params($self, ['ids', 'names']);
return $self->user_error($error, $vars) if $error;

if (defined(my $id_or_name = $self->stash('id'))) {
$params
Expand Down
4 changes: 2 additions & 2 deletions Bugzilla/API/V1/Product.pm
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ sub get {
my $user = $self->bugzilla->login;

my @list_params = qw(ids names type include_fields exclude_fields);
my ($params, $error) = merge_request_params($self, \@list_params);
return $self->user_error($error) if $error;
my ($params, $error, $vars) = merge_request_params($self, \@list_params);
return $self->user_error($error, $vars) if $error;

# A JSON body is merged in as-is, so a single value there is not yet a list;
# legacy validate() coerced it the same way.
Expand Down
20 changes: 10 additions & 10 deletions Bugzilla/API/V1/UserObject.pm
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ sub suggest {

my $user = $self->bugzilla->login;

my ($params, $error) = $self->_request_params;
return $self->user_error($error) if $error;
my ($params, $error, $vars) = $self->_request_params;
return $self->user_error($error, $vars) if $error;

Bugzilla->switch_to_shadow_db();

Expand Down Expand Up @@ -224,9 +224,9 @@ sub get {

my $api_user = $self->bugzilla->login;

my ($params, $error)
my ($params, $error, $vars)
= $self->_request_params(qw(names ids match group_ids groups ldap_emails));
return $self->user_error($error) if $error;
return $self->user_error($error, $vars) if $error;

if (defined(my $id_or_name = $self->stash('id_or_name'))) {
$params->{$id_or_name =~ /^\d+$/ ? 'ids' : 'names'} = [$id_or_name];
Expand Down Expand Up @@ -444,8 +444,8 @@ sub update {
|| return $self->user_error('auth_failure',
{group => 'editusers', action => 'edit', object => 'users'});

my ($params, $error) = $self->_request_params(qw(names ids));
return $self->user_error($error) if $error;
my ($params, $error, $vars) = $self->_request_params(qw(names ids));
return $self->user_error($error, $vars) if $error;

if (defined(my $id_or_name = $self->stash('id_or_name'))) {
$params
Expand Down Expand Up @@ -542,8 +542,8 @@ sub whoami {
|| return $self->user_error($self->_api_key_error // 'login_required');
}

my ($params, $error) = $self->_request_params;
return $self->user_error($error) if $error;
my ($params, $error, $vars) = $self->_request_params;
return $self->user_error($error, $vars) if $error;

# Generate a deterministic ID from the site-wide-secret and user-id.
# This can be used for user tracking in other systems without the
Expand Down Expand Up @@ -572,8 +572,8 @@ sub _request_params {
my ($self, @list_params) = @_;
push @list_params, qw(include_fields exclude_fields);

my ($params, $error) = merge_request_params($self, \@list_params);
return (undef, $error) if $error;
my ($params, $error, $vars) = merge_request_params($self, \@list_params);
return (undef, $error, $vars) if $error;

# A JSON body is merged in as-is, so a single value there is not yet a list;
# legacy validate() coerced it the same way.
Expand Down
54 changes: 45 additions & 9 deletions Bugzilla/API/V1/Util.pm
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ our @EXPORT_OK = qw(
filter_wants
merge_request_params
params_to_objects
render_options
set_rest_cors_headers
strip_request_params
translate
Expand Down Expand Up @@ -70,6 +71,15 @@ sub set_rest_cors_headers {
'Access-Control-Allow-Headers' => join(', ', @$allowed_headers));
}

# Answers a CORS preflight request with the methods in the route's "allow".
sub render_options {
my ($c) = @_;
my $allow = $c->stash('allow');
$c->res->headers->header('Allow' => $allow);
$c->res->headers->header('Access-Control-Allow-Methods' => $allow);
return $c->rendered(200);
}

sub extract_flags {
my ($flags, $bug, $attachment) = @_;
my (@new_flags, @old_flags);
Expand Down Expand Up @@ -318,6 +328,17 @@ sub merge_request_params {
$params = {%$body_params, %$params} if ref $body_params eq 'HASH';
}

# A list param sent as a single value in a JSON body is a list of one, and
# anything else that isn't a list of plain values, such as a hash or a
# nested list, is refused, as the legacy server's validate() did.
foreach my $name (sort keys %is_list) {
my $value = $params->{$name} // next;
$value = $params->{$name} = [$value] if !ref $value;
next if ref $value eq 'ARRAY' && !grep {ref} @$value;
return (undef, 'invalid_params',
{type_error => "$name must be a value or a list of values"});
}

return ($params, undef);
}

Expand All @@ -331,11 +352,14 @@ sub strip_request_params {
# A JSON body sends booleans as real booleans, but the query string and a form
# body send the literal string "true" or "false", which Perl treats as true
# either way. Turns each of the given params that is set into 1 or 0, and
# returns the error for the first one that isn't a boolean, if any.
# returns the error for the first one that isn't a boolean, if any. A JSON
# boolean is left as is; any other reference, such as [] or {}, is refused.
sub coerce_booleans {
my ($params, @fields) = @_;
foreach my $field (@fields) {
next if !defined $params->{$field} || ref $params->{$field};
next if !defined $params->{$field};
next if ref $params->{$field} eq 'JSON::PP::Boolean';
return "$field must be true or false" if ref $params->{$field};
my $value = lc $params->{$field};
return "$field must be true or false" if $value !~ /^(?:true|false|1|0)$/;
$params->{$field} = ($value eq 'true' || $value eq '1') ? 1 : 0;
Expand Down Expand Up @@ -601,6 +625,12 @@ Bugzilla::API::V1::Util - Helpers shared by the native API modules.

=head1 FUNCTIONS

=head2 render_options

Route callback answering an C<OPTIONS> (CORS preflight) request with the
methods given in the route's C<allow> stash value, e.g.
C<< $r->options('/foo')->to(cb => \&render_options, allow => 'GET, PUT') >>.

=head2 filter

This helps implement the C<include_fields> and C<exclude_fields> arguments
Expand Down Expand Up @@ -637,9 +667,9 @@ by both "ids" and "names". Returns an arrayref of objects.

=head2 merge_request_params

Takes a Mojolicious controller and returns a two-element list
C<($params, $error)>, merging its query string/form-body params with a
decoded JSON request body, if any. Query-string/form-body values win on a
Takes a Mojolicious controller and returns C<($params, $error, $vars)>,
merging its query string/form-body params with a decoded JSON request body,
if any. Query-string/form-body values win on a
key collision. For use by native Mojo REST controllers that need to accept
parameters from either the query string or a JSON body on non-GET
requests.
Expand All @@ -650,9 +680,15 @@ as arrayrefs, however many times they appear in the request; every other
parameter is always returned as a scalar. Declaring them is required because
a parameter's type must not depend on the number of occurrences sent.

If the request has a non-empty body that fails to decode as JSON, C<$params>
is C<undef> and C<$error> is set to C<rest_malformed_json>; callers should
pass it to C<user_error>. Otherwise C<$error> is C<undef>.
A list parameter sent as a single value in a JSON body is wrapped into a list
of one. One sent as anything else that is not a list of plain values, such as
a hash or a nested list, is refused.

On an error, C<$params> is C<undef>, C<$error> is the error and a third
element holds its variables; callers should pass both to C<user_error>.
C<$error> is C<rest_malformed_json> if the request has a non-empty body that
fails to decode as JSON, and C<invalid_params> if a list parameter is refused.
Otherwise C<$error> is C<undef>.

=head2 strip_request_params

Expand All @@ -675,4 +711,4 @@ Takes a params hashref and the names of boolean params, e.g.
C<coerce_booleans($params, qw(is_open has_unconfirmed))>. Each one that is set
to the string C<true>, C<false>, C<1> or C<0> (any case) becomes C<1> or C<0>;
a JSON boolean is left as is. Returns an error message for the first one that
is set to anything else, or C<undef>.
is set to anything else, including an array or a hash, or C<undef>.
17 changes: 2 additions & 15 deletions docs/en/md/api/core/v1/general.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,25 +105,12 @@ Preferences pages.
Send only one authentication method with each request. BMO does not combine
credentials or choose the strongest method when more than one is supplied.

All core resources have been migrated off the legacy authentication path onto
All resources have been migrated off the legacy authentication path onto
BMO's native REST framework, which accepts a cookie, an `X-Bugzilla-API-Key`
header, or an OAuth2 bearer token (plus the deprecated `Bugzilla_api_key`
and `api_key` query parameters described in the warning below, kept only as
a stopgap for undiscovered callers). Legacy `Bugzilla_login` and
`Bugzilla_password` credentials are **not** accepted on these resources, even
though the old WebService dispatcher underneath BMO still supports them for
resources not yet migrated (currently only some extension endpoints). On those
not-yet-migrated resources, if a request supplies both
`Bugzilla_login`/`Bugzilla_password` and an API key, BMO does not combine
them or choose the strongest method: the legacy credentials take precedence,
and BMO does not fall back to the API key if password authentication fails.

If the account has the **Require API key authentication for API requests**
preference enabled, a request to one of those not-yet-migrated resources
containing both valid username/password credentials and a valid API key fails
with an `API key authentication is required` error because BMO selected the
username/password credentials first. Remove the username/password credentials
and send only the API key; do not disable the preference.
`Bugzilla_password` credentials are **not** accepted.

**WARNING**: It should be noted that additional authentication methods exist,
but they are **not recommended** for use and are likely to be deprecated in
Expand Down
5 changes: 0 additions & 5 deletions extensions/Bitly/Extension.pm
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ our $VERSION = '1';

use Bugzilla;

sub webservice {
my ($self, $args) = @_;
$args->{dispatch}->{Bitly} = "Bugzilla::Extension::Bitly::WebService";
}

sub config_modify_panels {
my ($self, $args) = @_;
push @{$args->{panels}->{advanced}->{params}},
Expand Down
Loading