Files
InvoiceShelf/app/Policies/NotePolicy.php
Darko Gjorgjijoski e432e4e62f 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.
2026-06-12 09:17:52 +02:00

34 lines
870 B
PHP

<?php
namespace App\Policies;
use App\Models\Note;
use App\Models\User;
use Illuminate\Auth\Access\HandlesAuthorization;
use Silber\Bouncer\BouncerFacade;
class NotePolicy
{
use HandlesAuthorization;
public function manageNotes(User $user, ?Note $note = null)
{
if (! BouncerFacade::can('manage-all-notes', $note ?? Note::class)) {
return false;
}
// When acting on a specific note, enforce tenant isolation: the note
// must belong to a company the user is a member of.
return $note === null || $user->hasCompany($note->company_id);
}
public function viewNotes(User $user, ?Note $note = null)
{
if (! BouncerFacade::can('view-all-notes', $note ?? Note::class)) {
return false;
}
return $note === null || $user->hasCompany($note->company_id);
}
}