mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-07-17 14:25:21 +00:00
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:
committed by
GitHub
parent
c1cadb7ee0
commit
e432e4e62f
@@ -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);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user