A free open source IT asset/license management system
Check visibility in FMCS password reset
snipedd26b08d9086
diff --git a/app/Http/Controllers/Users/UsersController.php b/app/Http/Controllers/Users/UsersController.phpindex 71ca4061e3..4fce95aad5 100755--- a/app/Http/Controllers/Users/UsersController.php+++ b/app/Http/Controllers/Users/UsersController.php@@ -844,7 +844,12 @@ class UsersController extends Controller{$this->authorize('view', User::class);- if (($user = User::find($id)) && ($user->activated == '1') && ($user->email != '') && ($user->ldap_import == '0')) {+ $user = User::find($id);+ if ($user) {+ $this->authorize('view', $user);+ }++ if ($user && ($user->activated == '1') && ($user->email != '') && ($user->ldap_import == '0')) {$credentials = ['email' => trim($user->email)];try {diff --git a/tests/Feature/Users/Ui/SendPasswordResetAuthorizationTest.php b/tests/Feature/Users/Ui/SendPasswordResetAuthorizationTest.phpnew file mode 100644index 0000000000..22d28e95bd--- /dev/null+++ b/tests/Feature/Users/Ui/SendPasswordResetAuthorizationTest.php@@ -0,0 +1,89 @@+<?php++namespace Tests\Feature\Users\Ui;++use App\Models\Company;+use App\Models\User;+use Illuminate\Auth\Notifications\ResetPassword;+use Illuminate\Support\Facades\Notification;+use Tests\TestCase;++class SendPasswordResetAuthorizationTest extends TestCase+{+ public function test_send_password_reset_requires_view_permission(): void+ {+ $target = User::factory()->create();++ $this->actingAs(User::factory()->create())+ ->from(route('users.show', $target))+ ->post(route('users.password', $target->id))+ ->assertForbidden();+ }++ public function test_send_password_reset_does_not_leak_or_notify_cross_company_target_under_fmcs(): void+ {+ Notification::fake();+ $this->settings->enableMultipleFullCompanySupport();++ [$companyA, $companyB] = Company::factory()->count(2)->create();++ $admin = User::factory()->viewUsers()->forCompany($companyA)->create();+ $target = User::factory()->forCompany($companyB)->create();++ $response = $this->actingAs($admin)+ ->from(route('users.show', $target->id))+ ->post(route('users.password', $target->id));++ // No success flash carrying the target email, no reset dispatched,+ // and the response body must not contain the target email string.+ $this->assertNotSame('success', session()->get('_flash.new')[0] ?? null);+ $this->assertNull(session('success'));+ Notification::assertNothingSent();++ // Follow the redirect and check the rendered page doesn't leak+ // the target email into the flash text.+ if ($response->isRedirection()) {+ $followed = $this->actingAs($admin)->get($response->headers->get('Location'));+ $followed->assertDontSee($target->email);+ } else {+ $response->assertDontSee($target->email);+ }+ }++ public function test_send_password_reset_succeeds_for_same_company_target_under_fmcs(): void+ {+ Notification::fake();+ $this->settings->enableMultipleFullCompanySupport();++ $company = Company::factory()->create();+ $admin = User::factory()->viewUsers()->forCompany($company)->create();+ $target = User::factory()->forCompany($company)->create();++ $this->actingAs($admin)+ ->from(route('users.show', $target->id))+ ->post(route('users.password', $target->id))+ ->assertRedirect(route('users.show', $target->id))+ ->assertSessionHas('success');++ Notification::assertSentTo($target, ResetPassword::class);+ }++ public function test_send_password_reset_authorize_blocks_when_query_scope_is_bypassed(): void+ {+ // A superuser bypasses CompanyableScope on User queries. Even so,+ // for a non-existent user id the endpoint must not error out or+ // emit misleading output that leaks scope. Guarding sendPasswordReset+ // with an explicit view authorize keeps the failure path uniform+ // regardless of how User::find resolves.+ Notification::fake();++ $admin = User::factory()->superuser()->create();++ $this->actingAs($admin)+ ->from(route('users.index'))+ ->post(route('users.password', 999999999))+ ->assertRedirect();++ Notification::assertNothingSent();+ }+}