Skip to content

[6.x] Skip two factor setup enforcement while impersonating - #15247

Merged
jasonvarga merged 5 commits into
6.xfrom
impersonation-two-factor-setup
Aug 26, 2026
Merged

[6.x] Skip two factor setup enforcement while impersonating#15247
jasonvarga merged 5 commits into
6.xfrom
impersonation-two-factor-setup

Conversation

@duncanmcclean

Copy link
Copy Markdown
Member

This pull request fixes an issue where impersonating a user who hasn't set up two factor authentication (when it's enforced for their role) would redirect the impersonator to that user's 2FA setup screen, persisting a two_factor_secret and two_factor_recovery_codes onto the impersonated user's record in the process. Abandoning the setup didn't roll this back, and the impersonator could even complete the enrollment on the user's behalf.

This was happening because the RedirectIfTwoFactorSetupIncomplete middleware generates and saves a secret as a side effect of redirecting to the setup screen, and it didn't account for impersonation. Impersonation already bypasses the 2FA challenge, but not setup enforcement, which was inconsistent.

This PR fixes it by skipping the setup enforcement while impersonating, so the impersonator is never sent to the setup screen and nothing is written to the impersonated user's record. Enforcement kicks in as normal when the user next logs in themselves.

Fixes #15231

duncanmcclean and others added 5 commits August 24, 2026 10:14
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019fa8J46Th4Q3aRPWs51kPt
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019fa8J46Th4Q3aRPWs51kPt
The setup route is registered without the RedirectIfTwoFactorSetupIncomplete
middleware, so an impersonator could still reach it by navigating there
directly. Setup.vue posts to the enable endpoint on mount, which persists a
secret and recovery codes onto the impersonated user's record.

Guarding the base controller covers both the CP and frontend routes, since
the CP subclass only overrides redirectPath() and routes().

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@jasonvarga
jasonvarga merged commit 9518c55 into 6.x Aug 26, 2026
64 checks passed
@jasonvarga
jasonvarga deleted the impersonation-two-factor-setup branch August 26, 2026 16:50
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.

Impersonating a user who has never completed 2FA setup writes two_factor_secret and two_factor_recovery_codes to that user's record

2 participants