Bug 2075358 - Native Mojo REST endpoints serve anonymous requests when requirelogin is enabled - #2763
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The native Mojo login helper (
bugzilla.logininBugzilla/App/Plugin/Login.pm) upgrades the login type toLOGIN_REQUIREDwhen therequireloginparameter is on, but only acts on it for browser usage modes. For REST it falls through and returns the anonymous user, so native REST endpoints that allow anonymous access keep serving anonymous requests on a site that requires login. The legacy dispatcher'sBugzilla->login()refuses them withlogin_required.Filed as its own bug rather than fixed inside a migration PR, since it changes behaviour for every native REST endpoint at once. This PR stands on its own and does not depend on any other open PR.
Changes
Bugzilla/App/Plugin/Login.pm: when the login type isLOGIN_REQUIRED, the request is REST (USAGE_MODE_RESTorUSAGE_MODE_MOJO_REST) and no credentials authenticated, throwlogin_requiredinstead of returning the anonymous user. The usage mode is normalized toUSAGE_MODE_MOJO_RESTfirst, for the same reason as the existing normalization above it: routes that authenticate before switching modes (e.g./rest/configuration,/rest/bug/<id>/graph) would otherwise hit the legacy REST error path and return a 500t/app-login-requirelogin.t: withrequireloginon, anonymousGET /rest/configuration,GET /rest/classification/1andGET /rest/product_accessiblereturn 401 / code 410 and the same requests with an API key are not refused; withrequireloginoff, anonymous requests are let through againBugzilla/API/V1/Product.pm: remove the local_loginstopgap that Bug 2071907 - Migrate Product REST resource to native Mojo API #2762 shipped with;getandget_products_by_typecall the shared login helper againBehaviour changes
With
requireloginon, anonymous requests to these native endpoints now getlogin_required(HTTP 401, code 410) instead of data:GET /rest/bug/<id>/graph(BugGraph)GET /rest/classification/<id_or_name>GET /rest/component/<product>/<component>GET /rest/configurationGET /rest/config/component_teams[/<team>]Product's endpoints already behaved this way through their own stopgap; they now get it from the helper, with no visible change.
With
requireloginoff nothing changes, and authenticated requests are unaffected either way. Browser routes keep their existing redirect-to-login behaviour. Endpoints that authenticate by other means and never call the login helper (e.g. the GitHub webhooks) are unaffected.extensions/GitHubPullRequests/lib/API/V1/PullRequests.pmalready passesLOGIN_REQUIREDand checks$user->iditself, so it returns the same 401 as before, now from the helper.Test plan
t/app-login-requirelogin.tt/app-login-disabled-account.tpasses unchangedrequireloginon: anonymousGET /rest/configuration,GET /rest/classification/1andGET /rest/product_accessiblereturn 401 / code 410; the same with anX-Bugzilla-API-Keyheader succeedrequireloginoff: the same anonymous requests succeed as beforeNote
#2762 landed first with a local
_loginstopgap for this gap. Master is merged in, and this PR now removes it (see Changes).References