Laravel 2 min read

Can someone open another customer’s invoice in your Laravel app?

Use a two-account test to find missing Laravel permissions on record pages, downloads and exports, then put the rules in policies.

Can someone open another customer’s invoice in your Laravel app?

Sign in to a test copy as someone from Account A. Open an invoice they’re allowed to see. Now try the URL for an invoice that belongs to Account B. If they can open it, the application is exposing records across accounts. Repeat the check on the PDF download, the export and any API endpoint that serves the same data.

Write down who should see the invoice

For example, a billing user can view invoices for their own account. A support user can view them only for the accounts they’re assigned to. Check the account relationship as well as the role. Hiding the invoice link in the menu leaves the underlying URL reachable.

Make the failing test small enough to read

This is illustrative. Use your own model, route names and account setup. The example assumes the app returns 403 for a record the user cannot access. If your policy deliberately conceals the record with a 404, assert that instead.

$this->actingAs($billingUserFromAccountA)
    ->get(route('invoices.show', $invoiceFromAccountB))
    ->assertForbidden();

Pair it with a test that opens Account A’s invoice successfully. That catches a fix that blocks everybody. Use a Laravel policy for the record-level decision and apply it where the request is handled. For lists and exports, constrain which records the query can return as well.

Try the paths staff use to get work done

Follow the link from a saved email. Download a PDF directly. Export from a filtered list. Then revoke access and try the same URLs again. If a queued export is involved, check what happens when access is revoked between requesting the export and downloading the result.

If you’ve inherited an application with permissions spread across several screens, tell me which role and record you’re concerned about.

Need a hand with this?

Work directly with me on an existing Laravel application, from a focused assessment to ongoing development.

Talk directly to Adam

Share this article

Back to Blog