Confine every Account query to the authenticated user's tenant - #1
Merged
Conversation
Same cross-tenant IDOR as the other modules: mutations were authorised with a capability check alone, which every tenant's staff passes, so another company's id resolved fine and was then read, edited or deleted — here across the chart of accounts, invoices, payments, expenses and journal entries. The boundary now lives on the models via App\Models\Concerns\TenantScoped. 23 tables carry created_by; the four that do not (credit/debit note items, their taxes, vendor payment allocations) inherit it through their parent. 33 exists: rules are scoped by hand, since they go through the query builder and never see an Eloquent scope. Two of them point at sales_invoices and purchase_invoices, owned by another module — without scoping those, a payment could still be allocated against another company's invoice. AccountUtility provisions a NEW company's chart of accounts from someone else's session, so its five lookups opt out of the scope explicitly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes the cross-tenant IDOR in this module — the financial one: chart of accounts, invoices, payments, expenses, journal entries.
The fix
Same shape as zerp-pk/lead#1 and zerp-pk/hrm#1. The boundary goes on the models via the shared
App\Models\Concerns\TenantScoped(zerp-pk/zerp#5), so a foreign id resolves tonulland route-model binding 404s before a controller runs.23 tables carry
created_by. The four that do not — credit/debit note items, their taxes, and vendor payment allocations — declare a$tenantParentand inherit the boundary through it.The parts a model scope cannot cover
33
exists:rules scoped by hand — they go through the query builder and never see an Eloquent scope. Two of them are worth calling out:allocations.*.invoice_idpointed atsales_invoices/purchase_invoices, which are owned by another module. Unscoped, a payment could still be allocated against another company's invoice.AccountUtilityprovisions a new company's chart of accounts, often from a superadmin's session, so its five lookups opt out withwithoutGlobalScope("tenant"). Without that, signup would silently re-seed the chart of accounts on every run.Two
find()sites that dereference immediately becamefindOrFail(), so a foreign id is a 404 rather than a 500.Verification
Proven against real MySQL in a rolled-back transaction: two tenants, each sees its own chart-of-accounts row and category,
blockedon the other's, and the list shows 1 of 2 — it isolates without over-filtering. Child rows (credit_note_items, nocreated_byof their own) verified to scope throughcredit_notes.created_by. Covered bytests/Unit/TenantScopeTest.php.