From 34c0d2177d63be0b96fe2823b1915fcc92641507 Mon Sep 17 00:00:00 2001 From: David Lawrence Date: Sun, 29 Nov 2026 22:24:26 -0500 Subject: [PATCH] Bug 2099092 - Remove the obsolete api_key_only user preference now that the native REST API only accepts API keys, OAuth2 tokens, or cookie + api token All API endpoints now authenticate through the native Mojo login helper, which never consulted api_key_only and does not accept the username/password or login-token methods the preference blocked. The remaining checks in the legacy auth stack are unreachable from the API. - Drop the api_key_only checks from Auth::Login::Cookie and Auth::Verify::DB, along with the now unused invalid_auth_method error. - Remove the setting and delete existing rows via a new OBSOLETE_SETTINGS list processed by update_settings(). - Remove the MFA-gated save logic for the setting from userprefs.cgi and the related MFA page text, JS and CSS. - Remove the "(weakened)" marker and api_key_only field from the BMO group members report. --- Bugzilla/Auth/Login/Cookie.pm | 12 +--- Bugzilla/Auth/Verify/DB.pm | 8 --- Bugzilla/Install.pm | 26 ++++++--- extensions/BMO/lib/Reports/Groups.pm | 4 -- .../en/default/pages/group_members.html.tmpl | 1 - js/account.js | 6 +- skins/standard/admin.css | 1 - .../en/default/account/prefs/mfa.html.tmpl | 25 -------- .../default/account/prefs/settings.html.tmpl | 3 - .../en/default/global/setting-descs.none.tmpl | 1 - .../en/default/global/user-error.html.tmpl | 4 -- userprefs.cgi | 57 +------------------ 12 files changed, 25 insertions(+), 123 deletions(-) diff --git a/Bugzilla/Auth/Login/Cookie.pm b/Bugzilla/Auth/Login/Cookie.pm index a757cdfbe1..193a44463a 100644 --- a/Bugzilla/Auth/Login/Cookie.pm +++ b/Bugzilla/Auth/Login/Cookie.pm @@ -35,7 +35,7 @@ sub get_login_info { my ($self) = @_; my $cgi = Bugzilla->cgi; my $dbh = Bugzilla->dbh; - my ($user_id, $login_cookie, $is_internal); + my ($user_id, $login_cookie); $login_cookie = $cgi->cookie("Bugzilla_logincookie"); $user_id = $cgi->cookie("Bugzilla_login"); @@ -68,7 +68,6 @@ sub get_login_info { Bugzilla->check_rate_limit('token_mismatch'); ThrowUserError('auth_invalid_token', {token => $api_token}); } - $is_internal = 1; } elsif ($login_cookie && Bugzilla->usage_mode == USAGE_MODE_REST) { @@ -100,15 +99,6 @@ sub get_login_info { # If the cookie is valid, return a valid username. if (defined $db_cookie && secure_compare($cookie_hash, $db_cookie)) { - # forbid logging in with a cookie if only api-keys are allowed - if (i_am_webservice() && !$is_internal) { - my $user = Bugzilla::User->new({id => $user_id, cache => 1}); - if ($user->settings->{api_key_only}->{value} eq 'on') { - Bugzilla->check_rate_limit('token_mismatch'); - ThrowUserError('invalid_cookies_or_token'); - } - } - # If we logged in successfully, then update the lastused # time on the login cookie $dbh->do( diff --git a/Bugzilla/Auth/Verify/DB.pm b/Bugzilla/Auth/Verify/DB.pm index 3f02779d08..438baca3b3 100644 --- a/Bugzilla/Auth/Verify/DB.pm +++ b/Bugzilla/Auth/Verify/DB.pm @@ -124,14 +124,6 @@ sub check_credentials { $user->update(); } - if (i_am_webservice() && $user->settings->{api_key_only}->{value} eq 'on') { - - # api-key verification happens in Auth/Login/APIKey - # token verification happens in Auth/Login/Cookie - # if we get here from an api call then we must be using user/pass - return {failure => AUTH_ERROR, user_error => 'invalid_auth_method',}; - } - return $login_data; } diff --git a/Bugzilla/Install.pm b/Bugzilla/Install.pm index 15b65fb3fe..8b65589ed6 100644 --- a/Bugzilla/Install.pm +++ b/Bugzilla/Install.pm @@ -196,12 +196,6 @@ sub SETTINGS { default => 'on', category => 'Reviews and Needinfo' }, - { - name => 'api_key_only', - options => ['on', 'off'], - default => 'off', - category => 'API' - }, { name => 'autosize_comments', options => ['on', 'off'], @@ -217,6 +211,14 @@ sub SETTINGS { ]; } +# Settings that used to be defined in SETTINGS and must be deleted, along +# with any user choices for them, from existing installations. +use constant OBSOLETE_SETTINGS => ( + + # 2026-11-29 -- Bug 2099092 + 'api_key_only', +); + use constant SYSTEM_GROUPS => ( {name => 'admin', description => 'Administrators'}, {name => 'tweakparams', description => 'Can change Parameters'}, @@ -319,6 +321,10 @@ sub update_settings { foreach my $params (@settings) { add_setting($params); } + + foreach my $name (OBSOLETE_SETTINGS) { + remove_setting($name); + } } sub update_system_groups { @@ -590,6 +596,11 @@ issues after the database is completely set up and configured. Contains information about Settings, used by L. +=item C + +Names of Settings that are no longer used. L deletes +them, along with any user choices for them. + =back =head1 SUBROUTINES @@ -598,7 +609,8 @@ Contains information about Settings, used by L. =item C -Description: Adds and updates Settings for users. +Description: Adds and updates Settings for users, and removes any + listed in L. Params: none diff --git a/extensions/BMO/lib/Reports/Groups.pm b/extensions/BMO/lib/Reports/Groups.pm index 77faf3936c..1c0d21d220 100644 --- a/extensions/BMO/lib/Reports/Groups.pm +++ b/extensions/BMO/lib/Reports/Groups.pm @@ -251,10 +251,6 @@ sub members_report { $rh_user->{groups} = [$rh->{name}]; $rh_user->{lastseeon} = $member->last_seen_date; $rh_user->{mfa} = $member->mfa; - $rh_user->{api_key_only} - = $member->settings->{api_key_only}->{value} eq 'on' - ? JSON::true - : JSON::false; } $users{$login} = $rh_user; } diff --git a/extensions/BMO/template/en/default/pages/group_members.html.tmpl b/extensions/BMO/template/en/default/pages/group_members.html.tmpl index bd1219c6e4..afd77223bf 100644 --- a/extensions/BMO/template/en/default/pages/group_members.html.tmpl +++ b/extensions/BMO/template/en/default/pages/group_members.html.tmpl @@ -116,7 +116,6 @@ [% IF member.mfa %] [% member.mfa FILTER html %] - [% " (weakened)" IF member.settings.api_key_only.value == "off" %] [% ELSE %] - [% END %] diff --git a/js/account.js b/js/account.js index e716fdc8ed..544c17986d 100644 --- a/js/account.js +++ b/js/account.js @@ -96,7 +96,6 @@ $(function() { $('#update').attr('disabled', true); $('#mfa-totp-enable-code').attr('required', true); $('#mfa-confirm').show(); - $('.mfa-api-blurb').show(); $('#mfa-enable-shared').show(); $('#mfa-enable-totp').show(); $('#mfa-totp-throbber').show(); @@ -126,7 +125,6 @@ $(function() { $('#update').attr('disabled', false); $('#mfa-duo-user').attr('required', true); $('#mfa-confirm').show(); - $('.mfa-api-blurb').show(); $('#mfa-enable-shared').show(); $('#mfa-enable-duo').show(); $('#mfa-password').focus(); @@ -135,7 +133,7 @@ $(function() { $('#mfa-disable') .click(function(event) { event.preventDefault(); - $('.mfa-api-blurb, .mfa-buttons').hide(); + $('.mfa-buttons').hide(); $('#mfa-disable-container, #mfa-auth-container').show(); $('#mfa-confirm').show(); $('#mfa-password').focus(); @@ -147,7 +145,7 @@ $(function() { $('#mfa-recovery') .click(function(event) { event.preventDefault(); - $('.mfa-api-blurb, .mfa-buttons').hide(); + $('.mfa-buttons').hide(); $('#mfa-recovery-container, #mfa-auth-container').show(); $('#mfa-password').focus(); $('#update').attr('disabled', false).val('Generate Printable Recovery Codes'); diff --git a/skins/standard/admin.css b/skins/standard/admin.css index 549b4f68d1..111d4c6387 100644 --- a/skins/standard/admin.css +++ b/skins/standard/admin.css @@ -257,7 +257,6 @@ th.title { cursor: help; } -.mfa-api-blurb, .mfa-disable-blurb { width: 70%; } diff --git a/template/en/default/account/prefs/mfa.html.tmpl b/template/en/default/account/prefs/mfa.html.tmpl index 71c2c81290..f6dbe69bda 100644 --- a/template/en/default/account/prefs/mfa.html.tmpl +++ b/template/en/default/account/prefs/mfa.html.tmpl @@ -97,23 +97,6 @@ [% END %] -

- [% IF user.settings.api_key_only.value == 'on' %] - Enabling two-factor authentication has also required systems that - interface with [% terms.Bugzilla %]'s API to use API keys - for authentication.
-
- While not recommended, this limitation can be lifted by changing the - Require API key authentication for API requests - preference. - [% ELSE %] - Systems that interface with [% terms.Bugzilla %]'s API are not required to use API keys.
- Change the - Require API key authentication for API requests - preference to enforce API key usage. - [% END %] -

-

You will need to disable your two-factor authentication in order to change to a different method. There will be a small amount of time when your account will not be as secure, so you may use the @@ -289,14 +272,6 @@ Submit Changes.

- -

Warning: Changing your Two-factor authentication settings will automatically log out other login sessions except for the current one. diff --git a/template/en/default/account/prefs/settings.html.tmpl b/template/en/default/account/prefs/settings.html.tmpl index ff451a2309..1ea02dcdbc 100644 --- a/template/en/default/account/prefs/settings.html.tmpl +++ b/template/en/default/account/prefs/settings.html.tmpl @@ -70,9 +70,6 @@ [% END %] - [% IF setting_name == "api_key_only" %] - [% INCLUDE "mfa/protected.html.tmpl" %] - [% END %] [% END %] diff --git a/template/en/default/global/setting-descs.none.tmpl b/template/en/default/global/setting-descs.none.tmpl index 7f09a255c4..04c2e27f47 100644 --- a/template/en/default/global/setting-descs.none.tmpl +++ b/template/en/default/global/setting-descs.none.tmpl @@ -58,7 +58,6 @@ "bugmail_flag_prefix" => "Add the flag request or answer (e.g. 'needinfo requested:') to the start of the subject line of email about flags requested of me or answered for me", "possible_duplicates" => "Display possible duplicates when reporting a new $terms.bug", "requestee_cc" => "Automatically add me to the CC list of $terms.bugs I am requested to review", - "api_key_only" => "Require API key authentication for API requests", } %] diff --git a/template/en/default/global/user-error.html.tmpl b/template/en/default/global/user-error.html.tmpl index 09059ab93f..304cf43b26 100644 --- a/template/en/default/global/user-error.html.tmpl +++ b/template/en/default/global/user-error.html.tmpl @@ -1050,10 +1050,6 @@ [% title = "Invalid Attachment ID" %] The attachment id [% attach_id FILTER html %] is invalid. - [% ELSIF error == "invalid_auth_method" %] - [% title = "Invalid Authentication Method" %] - API key authentication is required. - [% ELSIF error == "invalid_params" %] [% title = "Invalid Params" %] API method received invalid params: [% type_error FILTER html %] diff --git a/userprefs.cgi b/userprefs.cgi index 854f9a1f1d..0e1359cb48 100755 --- a/userprefs.cgi +++ b/userprefs.cgi @@ -260,7 +260,6 @@ sub SaveSettings { my $settings = $user->settings; my @setting_list = keys %$settings; - my $mfa_event = undef; foreach my $name (@setting_list) { next if !($settings->{$name}->{'is_enabled'}); @@ -268,34 +267,14 @@ sub SaveSettings { next unless defined $value; my $setting = new Bugzilla::User::Setting($name); - if ( - $name eq 'api_key_only' - && $user->mfa - && ($value eq 'off' - || ($value eq 'api_key_only-isdefault' && $setting->{default_value} eq 'off')) - ) - { - $mfa_event = {}; - } - if ($value eq "${name}-isdefault") { if (!$settings->{$name}->{'is_default'}) { - if ($mfa_event) { - $mfa_event->{reset} = 1; - } - else { - $settings->{$name}->reset_to_default; - } + $settings->{$name}->reset_to_default; } } else { $setting->validate_value($value); - if ($name eq 'api_key_only' && $mfa_event) { - $mfa_event->{set} = $value; - } - else { - $settings->{$name}->set($value); - } + $settings->{$name}->set($value); } } @@ -303,32 +282,6 @@ sub SaveSettings { $vars->{'settings'} = $user->settings(1); clear_settings_cache($user->id); - - if ($mfa_event) { - $mfa_event->{reason} = 'Disabling API key authentication requirements'; - $mfa_event->{postback} - = {action => 'userprefs.cgi', fields => {tab => 'settings',},}; - $user->mfa_provider->verify_prompt($mfa_event); - } -} - -sub MfaSettings { - my $mfa_token = shift; - my $user = Bugzilla->user; - return unless $user->mfa; - - my $event = $user->mfa_provider->verify_token($mfa_token); - - my $settings = $user->settings; - if ($event->{reset}) { - $settings->{api_key_only}->reset_to_default(); - } - elsif (my $value = $event->{set}) { - $settings->{api_key_only}->set($value); - } - - $vars->{settings} = $user->settings(1); - clear_settings_cache($user->id); } sub DoEmail { @@ -794,9 +747,6 @@ sub SaveMFAupdate { $user->set_mfa($mfa); $user->mfa_provider->enrolled(); Bugzilla->request_cache->{mfa_warning} = 0; - my $settings = Bugzilla->user->settings; - $settings->{api_key_only}->set('on'); - clear_settings_cache(Bugzilla->user->id); $user->set_mfa_required_date(undef); # Clear requirement date if set @@ -1169,8 +1119,7 @@ SWITCH: for ($current_tab_name) { last SWITCH; }; /^settings$/ && do { - MfaSettings($mfa_token) if $mfa_token; - SaveSettings() if $save_changes; + SaveSettings() if $save_changes; DoSettings(); last SWITCH; };