A free open source IT asset/license management system
Scope consumables in bulk users controller the same as other items
snipe6d8f6f0b6d11
diff --git a/app/Http/Controllers/Users/BulkUsersController.php b/app/Http/Controllers/Users/BulkUsersController.phpindex 57c4cf203c..f2a0e0cda6 100644--- a/app/Http/Controllers/Users/BulkUsersController.php+++ b/app/Http/Controllers/Users/BulkUsersController.php@@ -433,6 +433,15 @@ class BulkUsersController extends Controller}}+ // Company-scoped consumable set: the CompanyableTrait's global+ // scope filters this to consumables the caller can actually+ // see. Used to fence the ConsumableAssignment delete below to+ // the caller's tenant, closing the FMCS bypass reported in+ // GHSA-m647-5cjf-gf92 while leaving the existing permission+ // model (editUsers alone can bulk-remove consumable pivots)+ // intact for same-company operations.+ $scopedConsumableIds = Consumable::whereIn('id', $consumableUserRows->pluck('consumable_id')->unique())->pluck('id');+if ($request->input('delete_user') == '1' && $users->isNotEmpty() && auth()->user()->cannot('delete', User::class)) {return redirect()->route('users.index')->with('error', trans('general.insufficient_permissions'));}@@ -449,7 +458,11 @@ class BulkUsersController extends Controller]);LicenseSeat::whereIn('id', $licenses->pluck('id'))->update(['assigned_to' => null]);- ConsumableAssignment::whereIn('id', $consumableUserRows->pluck('id'))->delete();++ $scopedConsumableRowIds = $consumableUserRows+ ->whereIn('consumable_id', $scopedConsumableIds)+ ->pluck('id');+ ConsumableAssignment::whereIn('id', $scopedConsumableRowIds)->delete();CheckoutAcceptance::pending()->whereIn('assigned_to_id', $user_raw_array)diff --git a/tests/Feature/Users/Ui/BulkActions/BulkCheckinConsumableFmcsTest.php b/tests/Feature/Users/Ui/BulkActions/BulkCheckinConsumableFmcsTest.phpnew file mode 100644index 0000000000..f233282bcb--- /dev/null+++ b/tests/Feature/Users/Ui/BulkActions/BulkCheckinConsumableFmcsTest.php@@ -0,0 +1,84 @@+<?php++namespace Tests\Feature\Users\Ui\BulkActions;++use App\Models\Company;+use App\Models\Consumable;+use App\Models\Statuslabel;+use App\Models\User;+use Illuminate\Support\Facades\DB;+use Tests\TestCase;++class BulkCheckinConsumableFmcsTest extends TestCase+{+ public function test_bulk_checkin_cannot_delete_consumable_pivot_rows_across_fmcs_boundary()+ {+ $this->settings->enableMultipleFullCompanySupport();++ $companyA = Company::factory()->create();+ $companyB = Company::factory()->create();++ $attacker = User::factory()->editUsers()->create();+ $attacker->companies()->sync([$companyA->id]);+ $attacker->syncLegacyCompanyIdMirror();++ $victim = User::factory()->create();+ $victim->companies()->sync([$companyB->id]);+ $victim->syncLegacyCompanyIdMirror();++ $companyBConsumable = Consumable::factory()->create(['company_id' => $companyB->id]);+ $victimAssignmentId = DB::table('consumables_users')->insertGetId([+ 'consumable_id' => $companyBConsumable->id,+ 'assigned_to' => $victim->id,+ 'created_by' => $victim->id,+ 'created_at' => now(),+ 'updated_at' => now(),+ ]);++ $this->actingAs($attacker)+ ->post(route('users/bulksave'), [+ 'ids' => [$victim->id],+ 'status_id' => Statuslabel::factory()->create()->id,+ ]);++ $this->assertDatabaseHas('consumables_users', [+ 'id' => $victimAssignmentId,+ 'consumable_id' => $companyBConsumable->id,+ 'assigned_to' => $victim->id,+ ]);+ }++ public function test_bulk_checkin_still_deletes_in_scope_consumable_pivot_rows()+ {+ $this->settings->enableMultipleFullCompanySupport();++ $companyA = Company::factory()->create();++ $actor = User::factory()->editUsers()->create();+ $actor->companies()->sync([$companyA->id]);+ $actor->syncLegacyCompanyIdMirror();++ $target = User::factory()->create();+ $target->companies()->sync([$companyA->id]);+ $target->syncLegacyCompanyIdMirror();++ $consumable = Consumable::factory()->create(['company_id' => $companyA->id]);+ $assignmentId = DB::table('consumables_users')->insertGetId([+ 'consumable_id' => $consumable->id,+ 'assigned_to' => $target->id,+ 'created_by' => $actor->id,+ 'created_at' => now(),+ 'updated_at' => now(),+ ]);++ $this->actingAs($actor)+ ->post(route('users/bulksave'), [+ 'ids' => [$target->id],+ 'status_id' => Statuslabel::factory()->create()->id,+ ]);++ $this->assertDatabaseMissing('consumables_users', [+ 'id' => $assignmentId,+ ]);+ }+}