fix(security): enforce company scope on notes, doc-convert, and member bulk-delete (#668)

v3 port of the v2 authorization fixes.

- Notes IDOR (GHSA-85wc): NotePolicy checks the note's company_id and
  NotesController passes the bound model to authorize() on show/update/destroy.
- Estimate<->Invoice convert IDOR (GHSA-j2vg): EstimatesController::convertToInvoice
  and InvoicesController::convertToEstimate authorize 'view' on the source
  document before creating the target.
- Member bulk-delete (GHSA-wxrv): MembersController scopes ids via
  User::whereCompany() before MemberService::delete.

Adds feature tests for cross-company 403s + same-company happy paths.
This commit is contained in:
Darko Gjorgjijoski
2026-06-12 11:02:08 +02:00
committed by GitHub
parent f3ab0f22fc
commit c6a00df120
9 changed files with 94 additions and 12 deletions

View File

@@ -1,5 +1,6 @@
<?php
use App\Models\Company;
use App\Models\Note;
use App\Models\User;
use Illuminate\Support\Facades\Artisan;
@@ -65,3 +66,28 @@ test('delete note', function () {
$this->assertModelMissing($note);
});
test('cannot retrieve a note belonging to another company', function () {
$note = Note::factory()->create(['company_id' => Company::factory()->create()->id]);
getJson("/api/v1/notes/{$note->id}")->assertStatus(403);
});
test('cannot update a note belonging to another company', function () {
$note = Note::factory()->create([
'company_id' => Company::factory()->create()->id,
'name' => 'original-name',
]);
putJson("/api/v1/notes/{$note->id}", Note::factory()->raw())->assertStatus(403);
$this->assertDatabaseHas('notes', ['id' => $note->id, 'name' => 'original-name']);
});
test('cannot delete a note belonging to another company', function () {
$note = Note::factory()->create(['company_id' => Company::factory()->create()->id]);
deleteJson("/api/v1/notes/{$note->id}")->assertStatus(403);
$this->assertModelExists($note);
});