A free open source IT asset/license management system
Fixed f7hg-289f - always return password reset form
snipef98543eaf906
diff --git a/app/Http/Controllers/Auth/ResetPasswordController.php b/app/Http/Controllers/Auth/ResetPasswordController.phpindex 997bacedac..4756414686 100644--- a/app/Http/Controllers/Auth/ResetPasswordController.php+++ b/app/Http/Controllers/Auth/ResetPasswordController.php@@ -63,23 +63,12 @@ class ResetPasswordController extends Controllerpublic function showResetForm(Request $request, $token = null){-- $credentials = $request->only('email', 'token');-- // Password::broker() is typed to return the interface- // Illuminate\Contracts\Auth\PasswordBroker, which doesn't- // declare getUser(). The concrete Illuminate\Auth\Passwords\- // PasswordBroker does. Narrow the type locally so PHPStan can- // resolve the method against the concrete class.- /** @var \Illuminate\Auth\Passwords\PasswordBroker $broker */- $broker = $this->broker();-- if (is_null($broker->getUser($credentials))) {- Log::debug('Password reset form FAILED - this token is not valid.');-- return redirect()->route('password.request')->with('error', trans('passwords.token'));- }-+ /*+ * Always render the form, regardless of whether the supplied email+ * resolves to an account to prevent email oracle.+ * Token + user validation now happens only in reset(),+ * which already returns identical responses for valid and invalid credentials.+ */return view('auth.passwords.reset')->with(['token' => $token,diff --git a/tests/Feature/Authentication/PasswordResetFormEnumerationTest.php b/tests/Feature/Authentication/PasswordResetFormEnumerationTest.phpnew file mode 100644index 0000000000..f14ebb2643--- /dev/null+++ b/tests/Feature/Authentication/PasswordResetFormEnumerationTest.php@@ -0,0 +1,71 @@+<?php++namespace Tests\Feature\Authentication;++use App\Models\User;+use Illuminate\Support\Facades\Cache;+use Tests\TestCase;++/*+ * Regression coverage for GHSA-f7hg-289f-972m (CWE-203 Observable Discrepancy).+ * GET /password/reset/{token}?email=... used to render the form (200) when the+ * email matched an account and redirect (302) otherwise, giving an+ * unauthenticated caller a reliable existence oracle.+ */+class PasswordResetFormEnumerationTest extends TestCase+{+ protected function setUp(): void+ {+ parent::setUp();++ // ResetPasswordController registers 'throttle:10,1' in its+ // constructor. The array cache driver keeps counters alive across+ // tests, so a prior run could trip the limit before the current+ // test gets its first request through. Clear it.+ Cache::flush();++ // CheckForSetup redirects every request to /setup when the users+ // table is empty, which would mask the enumeration behavior under+ // test. Seed one unrelated user so setup is considered complete.+ User::factory()->create();+ }++ public function test_known_and_unknown_emails_return_identical_responses(): void+ {+ $known = User::factory()->create([+ 'email' => '[email protected]',+ 'activated' => 1,+ ]);++ $knownResponse = $this->get('/password/reset/arbitrary-token?email='.urlencode($known->email));+ $unknownResponse = $this->get('/password/reset/[email protected]');++ $knownResponse->assertStatus(200);+ $unknownResponse->assertStatus(200);+ }++ public function test_form_renders_for_unknown_email_without_leaking_existence(): void+ {+ $response = $this->get('/password/reset/[email protected]');++ $response->assertStatus(200);+ // Form markup is identical regardless of whether the email was in+ // the users table.+ $response->assertSee('name="token"', false);+ $response->assertSee('name="username"', false);+ $response->assertSee('name="password"', false);+ }++ public function test_form_does_not_redirect_for_unknown_email(): void+ {+ /*+ * The old vulnerable branch sent unknown emails to a 302 with the+ * 'passwords.token' flash. Any 3xx on this endpoint re-opens the+ * enumeration oracle.+ */+ $response = $this->get('/password/reset/[email protected]');++ $this->assertLessThan(300, $response->status());+ $this->assertGreaterThanOrEqual(200, $response->status());+ }+}