Skip to content

Redirect authenticated users away from the password restore form - #1557

Open
LukeTowers wants to merge 1 commit into
developfrom
fix/restore-form-authenticated
Open

LukeTowers wants to merge 1 commit into
developfrom
fix/restore-form-authenticated

Conversation

@LukeTowers

Copy link
Copy Markdown
Member

The backend's password restore form is for signed-out users: it takes a login, sends that account a reset link, and reports the same thing either way. It has no notion of an acting user, while the code it calls does — Backend\Models\User::getResetPasswordCode() applies an authorization check when a user is signed in — so the form's behaviour could depend on whether a session was present, which it should not. Both restore() and restore_onSubmit() now redirect a signed-in user to the backend instead.

The guard is in both methods because Backend\Classes\Controller::run() dispatches AJAX handlers before the page action, so restore_onSubmit is reachable as the onSubmit handler on the restore action without restore() running at all.

Behaviour changes

  • A signed-in backend user who opens backend/auth/restore, or posts to it, is redirected to the backend rather than served the form. Signing out first still reaches it, which is the flow the form is for, and a user who wants to change their own password uses My Settings.

Tests

Backend\Tests\Controllers\AuthRestoreOracleTest. testAuthenticatedRestoreDoesNotRevealAccountExistence and testAuthenticatedRestoreAjaxHandlerDoesNotRevealAccountExistence fail without the change. testGuestRestoreResponseIsIdenticalForKnownAndUnknownLogins, testGuestRestoreStillIssuesACodeForAKnownAccount and testResetEndpointIsIdenticalForKnownAndUnknownUserIds are controls and pass either way.

modules/backend is green at 301 tests / 718 assertions; phpcs is clean on both files.

The backend's password restore form is for signed-out users: it takes a login, sends that account a reset link, and reports the same thing either way. It has no notion of an acting user, while the code it calls does — `Backend\Models\User::getResetPasswordCode()` applies an authorization check when a user is signed in — so the form's behaviour could depend on whether a session was present, which it should not. Both `restore()` and `restore_onSubmit()` now redirect a signed-in user to the backend instead.

The guard is in both methods because `Backend\Classes\Controller::run()` dispatches AJAX handlers before the page action, so `restore_onSubmit` is reachable as the `onSubmit` handler on the `restore` action without `restore()` running at all.

Behaviour changes:

- A signed-in backend user who opens `backend/auth/restore`, or posts to it, is redirected to the backend rather than served the form. Signing out first still reaches it, which is the flow the form is for, and a user who wants to change their own password uses My Settings.

Tests: `Backend\Tests\Controllers\AuthRestoreOracleTest` — `testAuthenticatedRestoreDoesNotRevealAccountExistence` and `testAuthenticatedRestoreAjaxHandlerDoesNotRevealAccountExistence` fail without the change; `testGuestRestoreResponseIsIdenticalForKnownAndUnknownLogins`, `testGuestRestoreStillIssuesACodeForAKnownAccount` and `testResetEndpointIsIdenticalForKnownAndUnknownUserIds` are controls that pass either way. `modules/backend` is green at 301 tests / 718 assertions and `phpcs` is clean.
@coderabbitai

coderabbitai Bot commented Sep 26, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 12 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 77fb2326-ff63-4539-aadc-62ac8deb51f3

📥 Commits

Reviewing files that changed from the base of the PR and between 4ab9e5a and 4d1292f.

📒 Files selected for processing (2)
  • modules/backend/controllers/Auth.php
  • modules/backend/tests/controllers/AuthRestoreOracleTest.php

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant