Skip to content

Commit 82851a7

Browse files
jasonvargaclaude
andcommitted
Always consume url.intended in 2FA challenge redirect resolution
The _redirect short-circuit returned early without pulling url.intended from session, which could leave a stale value behind when both were set. Pull it up front so it's consumed regardless of which path wins. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 0cd77d2 commit 82851a7

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

src/Http/Controllers/TwoFactorChallengeController.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,13 @@ protected function formAction()
8787

8888
protected function redirectPath(Request $request)
8989
{
90+
$intended = $request->session()->pull('url.intended', $this->defaultRedirectPath());
91+
9092
if (($redirect = $request->input('_redirect')) && ! URL::isExternalToApplication($redirect)) {
9193
return $redirect;
9294
}
9395

94-
return $request->session()->pull('url.intended', $this->defaultRedirectPath());
96+
return $intended;
9597
}
9698

9799
protected function defaultRedirectPath(): string

tests/Tags/User/TwoFactorChallengeFormTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,26 @@ public function it_uses_intended_url_from_session_when_no_redirect_param()
210210
$this->assertAuthenticatedAs($user);
211211
}
212212

213+
#[Test]
214+
public function it_clears_intended_url_from_session_when_redirect_param_wins()
215+
{
216+
$user = $this->userWithTwoFactorEnabled();
217+
218+
$this
219+
->session([
220+
'login.id' => $user->id(),
221+
'url.intended' => '/account',
222+
])
223+
->post(route('statamic.two-factor-challenge'), [
224+
'code' => $this->getOneTimeCode($user),
225+
'_redirect' => '/dashboard',
226+
])
227+
->assertRedirect('/dashboard')
228+
->assertSessionMissing('url.intended');
229+
230+
$this->assertAuthenticatedAs($user);
231+
}
232+
213233
private function user()
214234
{
215235
return tap(User::make()->makeSuper()->email('test@example.com'))->save();

0 commit comments

Comments
 (0)