fix(security): enforce company scope on notes, estimate-convert, and user bulk-delete (#661)

- Notes IDOR (GHSA-85wc): NotePolicy::viewNotes/manageNotes now receive the
  Note and require hasCompany($note->company_id); NotesController passes the
  bound model to authorize() on show/update/destroy.
- Estimate->Invoice IDOR (GHSA-j2vg): ConvertEstimateController authorizes
  'view' on the source estimate before creating the invoice.
- User bulk-delete (GHSA-wxrv): UsersController scopes candidate ids via
  User::whereCompany() before deletion so cross-company accounts are protected.

Adds feature tests for cross-company 403s plus same-company happy paths.
This commit is contained in:
Darko Gjorgjijoski
2026-06-12 09:17:52 +02:00
committed by GitHub
parent c1cadb7ee0
commit e432e4e62f
7 changed files with 81 additions and 19 deletions

View File

@@ -6,6 +6,7 @@ use App\Http\Requests\DeleteEstimatesRequest;
use App\Http\Requests\EstimatesRequest;
use App\Http\Requests\SendEstimatesRequest;
use App\Mail\SendEstimateMail;
use App\Models\Company;
use App\Models\Estimate;
use App\Models\EstimateItem;
use App\Models\Tax;
@@ -247,6 +248,16 @@ test('create invoice from estimate', function () {
$response->assertStatus(200);
});
test('cannot convert an estimate belonging to another company', function () {
$estimate = Estimate::factory()->create([
'company_id' => Company::factory()->create()->id,
'estimate_date' => now(),
'expiry_date' => now()->addMonth(),
]);
postJson("api/v1/estimates/{$estimate->id}/convert-to-invoice")->assertStatus(403);
});
test('delete multiple estimates using a form request', function () {
$this->assertActionUsesFormRequest(
EstimatesController::class,