mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-07-16 22:05:20 +00:00
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.
34 lines
870 B
PHP
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);
|
|
}
|
|
}
|