A free open source IT asset/license management system
Fixed FD-57829 / pfqh-g6vj - tighten scopes on requests in FMCS
snipe4d98fe642e45
diff --git a/app/Http/Controllers/Api/CheckoutRequest.php b/app/Http/Controllers/Api/CheckoutRequest.phpindex 13f18a52fb..ea1991ddcf 100644--- a/app/Http/Controllers/Api/CheckoutRequest.php+++ b/app/Http/Controllers/Api/CheckoutRequest.php@@ -79,21 +79,34 @@ class CheckoutRequest extends Controller$query->TextSearch($request->input('search'));}- // Pull the (search-narrowed) set; sort happens in PHP after+ // Pull the (search-narrowed) set. The sort happens in PHP after// the FMCS filter below since the controller loads all-then-// slice anyway. This also lets `remaining` sort work// uniformly across the polymorphic requestable types (each// computes numRemaining() differently, so a single DB// orderBy wouldn't cover them). Default sort: most recent- // first, matches the pre-change behavior when no client-side+ // first, which matches the previous behavior when no client-side// header is chosen.$requests = $query->get();if (Company::isFullMultipleCompanySupportEnabled() && ! auth()->user()->isSuperUser()) {- $requests = $requests->filter(- fn (CheckoutRequestModel $r) => $r->requestable- && Company::isCurrentUserHasAccess($r->requestable)- )->values();+ $requests = $requests->filter(function (CheckoutRequestModel $r): bool {+ if (!$r->requestable || !Company::isCurrentUserHasAccess($r->requestable)) {+ return false;+ }++ // AssetModel is a global object with no+ // company_id column, so Company::isCurrentUserHasAccess+ // short-circuits to true for every actor. Fall back to+ // the requesting user's tenant visibility, which+ // routes through User's CompanyableScope and correctly+ // rejects cross-company users.+ if ($r->requestable_type === AssetModel::class) {+ return $r->user !== null && Company::isCurrentUserHasAccess($r->user);+ }++ return true;+ })->values();}// Per-row checkout-permission filter. A caller who candiff --git a/tests/Feature/Requests/Api/IndexCheckoutRequestsTest.php b/tests/Feature/Requests/Api/IndexCheckoutRequestsTest.phpindex cebc4bbb7a..6a7a42e106 100644--- a/tests/Feature/Requests/Api/IndexCheckoutRequestsTest.php+++ b/tests/Feature/Requests/Api/IndexCheckoutRequestsTest.php@@ -428,6 +428,36 @@ class IndexCheckoutRequestsTest extends TestCase$this->assertNotContains($requestForB->id, $ids);}+ public function test_fmcs_hides_assetmodel_parent_requests_filed_by_other_tenants(): void+ {+ [$companyA, $companyB] = Company::factory()->count(2)->create();++ $adminInA = $companyA->users()->save(User::factory()->checkoutAssets()->make());+ $requesterInB = $companyB->users()->save(User::factory()->make());++ $sharedModel = AssetModel::factory()->create();++ $foreignRequest = CheckoutRequest::factory()->create([+ 'user_id' => $requesterInB->id,+ 'requestable_id' => $sharedModel->id,+ 'requestable_type' => AssetModel::class,+ 'notes' => 'CAND15-CROSS-TENANT-NOTE',+ ]);++ $this->settings->enableMultipleFullCompanySupport();++ $response = $this->actingAsForApi($adminInA)+ ->getJson(route('api.requests.index'))+ ->assertOk();++ $ids = collect($response->json('rows'))->pluck('id')->all();+ $this->assertNotContains($foreignRequest->id, $ids, 'Company A admin must not see Company B user\'s AssetModel request.');++ // Confirm the attacker-visible note never leaks into the+ // response body either, independent of the id check.+ $this->assertStringNotContainsString('CAND15-CROSS-TENANT-NOTE', $response->getContent());+ }+public function test_fmcs_floater_mode_surfaces_null_company_items_to_scoped_admins(): void{// Floater mode intentionally makes company_id=null itemsdiff --git a/tests/Feature/Requests/Ui/BulkCancelRequestTest.php b/tests/Feature/Requests/Ui/BulkCancelRequestTest.phpindex 5011bc61de..1ce8d8f5c9 100644--- a/tests/Feature/Requests/Ui/BulkCancelRequestTest.php+++ b/tests/Feature/Requests/Ui/BulkCancelRequestTest.php@@ -95,6 +95,42 @@ class BulkCancelRequestTest extends TestCase);}+ public function test_fmcs_prevents_bulk_cancel_of_assetmodel_parent_requests_filed_by_other_tenants(): void+ {+ // Regression for CAND-15 (Wojciech Ciemski). AssetModel has no+ // company_id, so Company::isCurrentUserHasAccess on the+ // requestable short-circuits to true for every actor. A+ // non-superuser in Company A could bulk-cancel a Company B+ // user's pending AssetModel-parent request. Fix adds a second+ // isCurrentUserHasAccess check on the requesting user, which+ // routes through User's CompanyableScope.+ $this->settings->enableMultipleFullCompanySupport();++ [$companyA, $companyB] = Company::factory()->count(2)->create();++ $adminInA = $companyA->users()->save(User::factory()->checkoutAssets()->make());+ $requesterInB = $companyB->users()->save(User::factory()->make());++ $sharedModel = \App\Models\AssetModel::factory()->create();++ $foreignRequest = CheckoutRequest::factory()->create([+ 'user_id' => $requesterInB->id,+ 'requestable_id' => $sharedModel->id,+ 'requestable_type' => \App\Models\AssetModel::class,+ ]);++ $this->actingAs($adminInA)+ ->post(route('requests.bulk-cancel'), [+ 'ids' => [$foreignRequest->id],+ ])+ ->assertRedirectToRoute('requests.index');++ $this->assertNull(+ $foreignRequest->fresh()->canceled_at,+ 'Cross-tenant AssetModel-parent request must not be canceled by Company A admin.'+ );+ }+public function test_superuser_can_cancel_across_companies(): void{$this->settings->enableMultipleFullCompanySupport();