Stack

How to security test a Laravel app

Updated

Laravel's failure mode is an authorization method that exists and is never invoked. Test by requesting every controller action with a second user's model id and checking whether a policy denies it, then by posting extra fields to see what $fillable accepts.

Where this class of bug actually lives in a Laravel app

  • Policies never called. php artisan make:policy generates the class; you still have to write $this->authorize('view', $invoice) in the controller, and the action added later usually does not.
  • Route-model binding. Route::get('/invoices/{invoice}') resolves any invoice by id before your code runs, so the controller receives another tenant's model.
  • $fillable and $guarded. $guarded = [] means every column is mass assignable, which includes is_admin and tenant_id.
  • Blade escaping bypasses. {!! $value !!} renders unescaped. One of those around a user-supplied field is stored XSS.

What to try first

  1. Grep the controllers for authorize( and list the actions that never call it, then hit those with a low-privilege user.
  2. Change the bound model id in each route to another tenant's and compare with a nonexistent id.
  3. POST is_admin=1 and tenant_id=<other> to every update endpoint.
  4. Look for {!! !!} around any field a user can write.

A reproduction you can keep

Route-model binding plus a missing policy is the whole bug. One request proves it:

Bound model, wrong tenant
curl -sS -i https://staging.example.com/invoices/1003 \
  -H 'Cookie: laravel_session=***' \
  -H 'X-XSRF-TOKEN: ***'

curl -sS -i https://staging.example.com/invoices/99999999 \
  -H 'Cookie: laravel_session=***'

# vulnerable: 200 with the invoice, and a 404 for the fake id
# fixed: both 404 with the same page

What "fixed" has to look like

Bind through a scoped query — Route::get('/invoices/{invoice}', ...)->scopeBindings() with a tenancy scope on the relationship — so the foreign id fails to resolve and returns 404. The control comparison above is the test.

Where people get this wrong

  • Gate::before in a service provider can silently allow every ability for one role, which looks like working authorization.
  • password and remember_token in $fillable turn an update route into account takeover.
  • Laravel's debug page on APP_DEBUG=true exposes environment variables in the response.

What Offense does here

Offense runs an agent swarm against your app in a disposable sandbox, keeps the request, the identity and the vulnerable response as evidence, and replays the same attack after the fix so the retest is a control comparison rather than a green check. It does not read your source and it does not patch your code: the finding goes to your coding agent with the reproduction attached. The hosted workspace is invite-only — join the waitlist — and the free dependency audit in /install needs no account.

Questions this page answers

Why does a Laravel policy exist and still not block anything?

Because a policy class does nothing until a controller calls authorize(), a form request calls authorize(), or middleware maps the model to it.

Is route-model binding an authorization check?

No. It resolves the record by id. Whether the caller may see it is a separate decision your code has to make.

Written by Offense Research, reviewed December 2, 2026. Correct something? Email imran@offenseresearch.com.