A free open source IT asset/license management system
Fixed jh96-jm2x-38qp - tightened scoping on bulk user checkin
snipe74d2e54cb5ab
diff --git a/app/Http/Controllers/Users/BulkUsersController.php b/app/Http/Controllers/Users/BulkUsersController.phpindex 17c12b4a07..9c50f8a0f1 100644--- a/app/Http/Controllers/Users/BulkUsersController.php+++ b/app/Http/Controllers/Users/BulkUsersController.php@@ -450,13 +450,18 @@ class BulkUsersController extends Controller// intact for same-company operations.$scopedConsumableIds = Consumable::whereIn('id', $consumableUserRows->pluck('consumable_id')->unique())->pluck('id');+ // Filter the raw pivot rows down to the scoped-parent id sets+ // computed above.+ $scopedAccessoryUserRows = $accessoryUserRows->whereIn('accessory_id', $accessoryModels->pluck('id'));+ $scopedLicenseSeats = $licenses->whereIn('license_id', $licenseModels->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'));}$this->logItemCheckinAndDelete($assets, Asset::class);- $this->logAccessoriesCheckin($accessoryUserRows);- $this->logItemCheckinAndDelete($licenses, License::class);+ $this->logAccessoriesCheckin($scopedAccessoryUserRows);+ $this->logItemCheckinAndDelete($scopedLicenseSeats, License::class);Asset::whereIn('id', $assets->pluck('id'))->update(['status_id' => e(request('status_id')),@@ -465,7 +470,7 @@ class BulkUsersController extends Controller'expected_checkin' => null,]);- LicenseSeat::whereIn('id', $licenses->pluck('id'))->update(['assigned_to' => null]);+ LicenseSeat::whereIn('id', $scopedLicenseSeats->pluck('id'))->update(['assigned_to' => null]);$scopedConsumableRowIds = $consumableUserRows->whereIn('consumable_id', $scopedConsumableIds)diff --git a/tests/Feature/Users/Ui/BulkActions/BulkCheckinAuditLogForgeryFmcsTest.php b/tests/Feature/Users/Ui/BulkActions/BulkCheckinAuditLogForgeryFmcsTest.phpnew file mode 100644index 0000000000..d79817750d--- /dev/null+++ b/tests/Feature/Users/Ui/BulkActions/BulkCheckinAuditLogForgeryFmcsTest.php@@ -0,0 +1,162 @@+<?php++namespace Tests\Feature\Users\Ui\BulkActions;++use App\Models\Accessory;+use App\Models\Actionlog;+use App\Models\Company;+use App\Models\License;+use App\Models\LicenseSeat;+use App\Models\Statuslabel;+use App\Models\User;+use Illuminate\Support\Facades\DB;+use Tests\TestCase;++/**+ * GHSA-jh96-jm2x-38qp regression coverage. Before the fix, the bulk+ * user checkin endpoint iterated raw `DB::table('accessories_checkout')`+ * and `DB::table('license_seats')` rows straight into the audit-log+ * writers, so a company-A caller POSTing a company-B victim id+ * forged `'checkin from'` Actionlog entries into the victim tenant's+ * audit stream even though the underlying pivot rows stayed put.+ */+class BulkCheckinAuditLogForgeryFmcsTest extends TestCase+{+ public function test_bulk_checkin_does_not_write_action_logs_for_foreign_company_accessories(): void+ {+ $this->settings->enableMultipleFullCompanySupport();++ $companyA = Company::factory()->create();+ $companyB = Company::factory()->create();++ $attacker = User::factory()->editUsers()->checkinAccessories()->create();+ $attacker->companies()->sync([$companyA->id]);+ $attacker->syncLegacyCompanyIdMirror();++ $victim = User::factory()->create();+ $victim->companies()->sync([$companyB->id]);+ $victim->syncLegacyCompanyIdMirror();++ $foreignAccessory = Accessory::factory()->create(['company_id' => $companyB->id]);+ DB::table('accessories_checkout')->insert([+ 'accessory_id' => $foreignAccessory->id,+ 'assigned_to' => $victim->id,+ 'assigned_type' => User::class,+ 'created_by' => $victim->id,+ 'created_at' => now(),+ ]);++ $this->actingAs($attacker)+ ->post(route('users/bulksave'), [+ 'ids' => [$victim->id],+ 'status_id' => Statuslabel::factory()->create()->id,+ ]);++ $this->assertDatabaseMissing('action_logs', [+ 'item_type' => Accessory::class,+ 'item_id' => $foreignAccessory->id,+ 'target_id' => $victim->id,+ 'action_type' => 'checkin from',+ ]);+ }++ public function test_bulk_checkin_does_not_write_action_logs_for_foreign_company_license_seats(): void+ {+ $this->settings->enableMultipleFullCompanySupport();++ $companyA = Company::factory()->create();+ $companyB = Company::factory()->create();++ $attacker = User::factory()->editUsers()->checkinLicenses()->create();+ $attacker->companies()->sync([$companyA->id]);+ $attacker->syncLegacyCompanyIdMirror();++ $victim = User::factory()->create();+ $victim->companies()->sync([$companyB->id]);+ $victim->syncLegacyCompanyIdMirror();++ $foreignLicense = License::factory()->create(['company_id' => $companyB->id, 'seats' => 3]);+ LicenseSeat::factory()->for($foreignLicense)->assignedToUser($victim)->create();++ $this->actingAs($attacker)+ ->post(route('users/bulksave'), [+ 'ids' => [$victim->id],+ 'status_id' => Statuslabel::factory()->create()->id,+ ]);++ $this->assertDatabaseMissing('action_logs', [+ 'item_type' => License::class,+ 'item_id' => $foreignLicense->id,+ 'target_id' => $victim->id,+ 'action_type' => 'checkin from',+ ]);+ }++ public function test_bulk_checkin_still_writes_action_logs_for_in_company_accessories(): void+ {+ $this->settings->enableMultipleFullCompanySupport();++ $companyA = Company::factory()->create();++ $actor = User::factory()->editUsers()->checkinAccessories()->create();+ $actor->companies()->sync([$companyA->id]);+ $actor->syncLegacyCompanyIdMirror();++ $target = User::factory()->create();+ $target->companies()->sync([$companyA->id]);+ $target->syncLegacyCompanyIdMirror();++ $accessory = Accessory::factory()->create(['company_id' => $companyA->id]);+ DB::table('accessories_checkout')->insert([+ 'accessory_id' => $accessory->id,+ 'assigned_to' => $target->id,+ 'assigned_type' => User::class,+ 'created_by' => $actor->id,+ 'created_at' => now(),+ ]);++ $this->actingAs($actor)+ ->post(route('users/bulksave'), [+ 'ids' => [$target->id],+ 'status_id' => Statuslabel::factory()->create()->id,+ ]);++ $this->assertDatabaseHas('action_logs', [+ 'item_type' => Accessory::class,+ 'item_id' => $accessory->id,+ 'target_id' => $target->id,+ 'action_type' => 'checkin from',+ ]);+ }++ public function test_bulk_checkin_still_writes_action_logs_for_in_company_license_seats(): void+ {+ $this->settings->enableMultipleFullCompanySupport();++ $companyA = Company::factory()->create();++ $actor = User::factory()->editUsers()->checkinLicenses()->create();+ $actor->companies()->sync([$companyA->id]);+ $actor->syncLegacyCompanyIdMirror();++ $target = User::factory()->create();+ $target->companies()->sync([$companyA->id]);+ $target->syncLegacyCompanyIdMirror();++ $license = License::factory()->create(['company_id' => $companyA->id, 'seats' => 3]);+ LicenseSeat::factory()->for($license)->assignedToUser($target)->create();++ $this->actingAs($actor)+ ->post(route('users/bulksave'), [+ 'ids' => [$target->id],+ 'status_id' => Statuslabel::factory()->create()->id,+ ]);++ $this->assertDatabaseHas('action_logs', [+ 'item_type' => License::class,+ 'item_id' => $license->id,+ 'target_id' => $target->id,+ 'action_type' => 'checkin from',+ ]);+ }+}