SkilVaultSign inStart free

Catalogue / laravel-authorization-review

laravel-authorization-review

MITSignedUse when reviewing authorization / access control in a Laravel project — find IDOR / broken object-level authorization (BOLA), audit which routes are unprotected, check policy / gate coverage, or sanity-check a new endpoint in a PR. Walks the authorization chain of every HTTP route (middleware → aut…
---
name: laravel-authorization-review
description: "Use when reviewing authorization / access control in a Laravel project — find IDOR / broken object-level authorization (BOLA), audit which routes are unprotected, check policy / gate coverage, or sanity-check a new endpoint in a PR. Walks the authorization chain of every HTTP route (middleware → authorize/policy/gate → query scoping → API Resource output), anchors every finding to real `php artisan route:list --json` output plus a cited `file:line`, classifies by evidence, and produces a per-route coverage map. Read-only / advise-only — never edits code."
license: MIT
metadata:
  author: "Petr Král (pekral.cz)"
---

Constraints

  • Apply @rules/php/core-standards.md
  • Apply @rules/laravel/laravel.md and @rules/laravel/architecture.md
  • Apply @rules/security/backend.md — *Database* (authentication & authorization, least privilege) and *Safe Validation & Error Messages* (a 403-vs-404 distinction that confirms a resource exists is itself an authorization-granularity leak)
  • Apply @rules/code-review/general.md — map every finding onto the CR severity scale (Critical / Moderate) so this skill plugs into a Laravel CR run
  • Advise-only. Reads files and runs one read-only command (php artisan route:list --json). Never edits routes, controllers, policies, or any source; emits a report plus fix sketches for a human to apply.
  • Apply @rules/reports/general.md — output in English, or in the language the project manifest sets in language.github when the findings fold into the GitHub PR comment (*Project override — language.github in the manifest*).

---

Modes

This skill runs in one of two modes, selected by the caller via MODE (default audit):

  • `audit` (default) — the full walk below: every application route in the inventory, the per-route coverage map, and the whole report template. Every section behaves as written unless it is explicitly flagged for MODE=cr.
  • `cr` (read-only lens — invoked by `@skills/code-review/SKILL.md`, `code-review-github`, `code-review-jira`, and `code-review-bugsnag` when the diff touches an authorization surface) — never modify a route, a controller, a policy, or any other file, never author a test, never stage / commit / push, never run a fixer or a checker, and never chain a follow-up review. The one command the lens runs stays the read-only php artisan route:list --json of step 1. Scope the walk to the routes the PR diff touches — step 1.3's intersection with the changed files is mandatory here, not optional — and return the findings as markdown carrying the reproducer fields the CR folds into its standard Critical / Moderate buckets. Emit every fix as a written snippet, never applied.

> What this lens owns in a CR: object-level authorization — whether the record a changed route reads, returns, or writes is scoped to the actor who asked for it (IDOR / BOLA), and whether that route's middleware → policy / gate → scoping → Resource-output chain authorizes at all. It reports on the routes the diff touched and never on a pre-existing route it did not. > What it does not render on a CR: the per-route coverage map and the standalone report header of templates/report.md. A CR carries findings, and the coverage map is an audit artifact. > Evidence still governs severity. A route whose exposure rests on a point the code does not settle is reported at the severity its verified facts support and is never promoted to close the gap — *Evidence & honesty* below is unchanged by this mode. When route:list will not boot, the lens runs on the static fallback of step 1.4, reports it as not verified, and moves every structural finding to the open-point class.

---

Scope

> SAST tells you where data flows. This tells you where it flows to the wrong user.

This skill is the judgment layer for the one category automated scanners structurally cannot do: broken object-level authorization (IDOR / BOLA) — #1 in the OWASP API Security Top 10. Taint scanners trace untrusted *input*; they cannot decide whether Order::find($id) *should* have been scoped to the current user. That is a question about intent, reasoned across middleware, controller, policy, and query.

The skill is trustworthy because every finding traces to a ground-truth anchor: php artisan route:list --json is the deterministic inventory of every endpoint and its merged middleware. If you cannot point to both a real route and a cited file:line, you do not report it.

---

Use when

  • The user wants to review authorization / access control or hunt for IDOR (broken object-level authorization)
  • A Laravel CR run needs to verify that new or changed routes are scoped to their owner
  • The user asks "which routes have no auth", "is this endpoint scoped to the owner", "do my controllers check policies", or "audit access control before launch"
  • A PR introduces or changes routes, controllers, policies, gates, FormRequests, or API Resources

This skill complements @skills/laravel-security/SKILL.md (broad 7-area audit) and the generic @skills/security-review/SKILL.md by going deep on the authorization chain with a route-inventory anchor. Use it as the focused authorization lane inside a Laravel CR.

---

Method

Work the steps in order. Step 1 is non-negotiable: every finding traces to the real route inventory and a cited controller line, never to a guess about what the code "probably" does.

1. Ground truth from route:list

  1. Confirm it's a Laravel project — artisan at the repo root plus app/ / routes/. If absent, stop and say so.
  2. Get the route inventory — the anchor:
   php artisan route:list --json

Returns, per route: HTTP method, uri, name, the full merged middleware list, and action. This is the spine you reason about and the source of truth for *what middleware actually applies* (route-group middleware is already merged in). > --json renders middleware as resolved class strings, not aliases: > can:update,post → Illuminate\Auth\Middleware\Authorize:update,post; > auth:sanctum → Illuminate\Auth\Middleware\Authenticate:sanctum; a custom > role:admin → its own class. Never decide "no authz" by grepping for the literal > `can:` — match the Authorize: / class form too, and read any custom middleware > class. See references/auth-patterns.md §2a.

  1. Scope the review to application routes — skip framework / vendor routes unless asked. A debug or management dashboard (telescope, horizon, pulse, _ignition) that the diff changes is never skipped: it is an internal route (@rules/security/backend.md *Route Access (issue #586)*). For a PR / diff, intersect the route list with the changed files.
  2. Fallback when the app won't boot: parse routes/*.php statically + Grep for Route:: / middleware, report it as not verified (Not verified: route middleware — php artisan route:list did not boot; routes read statically.), and move every structural finding to the open-point class: the merged route-group middleware is exactly what the static read cannot see. Never silently substitute a guess for the real list.

> Laravel 11/12 boots route:list on defaults even with no .env — a missing .env is *not* a reliable failure trigger. Real boot failures: a missing PHP extension, or a service provider that hits the DB / cache at boot. If it's a missing extension you can enable, prefer fixing the boot (php -d extension=gd artisan route:list --json) over the lossy static fallback. Glob all of routes/*.php — apps split into admin.php, api.base.php, etc.

2. The authorization chain — four layers per route

On a large app, establish the convention first, then audit by exception: find how the app authorizes (base controller AuthorizesRequests? policies auto-discovered or registered? object scoping inline or in a repository / custom Builder? auth per-route or per group?), then most routes are a fast conformance check and the findings are the deviations.

For each in-scope route, record which layers are present:

| Layer | Present when (fact you can cite) | Where to look | |-------|----------------------------------|---------------| | 1 · Authentication | auth, auth:sanctum, auth:api, or a custom guard in the route's middleware | route:list | | 2 · Authorization | can: middleware (renders as Illuminate\Auth\Middleware\Authorize:<ability>) OR Gate::authorize/allows/denies / $this->authorize() (needs AuthorizesRequests) / $user->can() OR authorizeResource() in the constructor OR a FormRequest whose authorize() returns a *real* check | route:list + controller / request | | 3 · Object scoping (IDOR core) | the record is fetched scoped to the actor ($request->user()->posts()->findOrFail(...), scoped route binding) OR authorized against the bound model (authorize('update', $post)) | controller method | | 4 · Policy exists | an App\Policies\{Model}Policy is auto-discovered, bound via #[UsePolicy], or registered with Gate::policy(...) (in AppServiceProvider::boot() on L11+, or AuthServiceProvider::$policies on ≤10) | filesystem + provider |

> Laravel-version note. Since Laravel 11 the base Controller is empty and does > not include AuthorizesRequests, so $this->authorize() / authorizeResource() > exist only when the controller adds use AuthorizesRequests;; the always-available > form is Gate::authorize(...). AuthServiceProvider is gone from the skeleton — > policies are registered in AppServiceProvider::boot(), via #[UsePolicy], or > auto-discovered. Recognize all of these. See references/auth-patterns.md.

3. The IDOR core — object-level authorization (the flagship)

  • Implicit route-model binding resolves, it does NOT authorize. public function update(Post $post) loads *anyone's* post by id. Without authorize('update', $post) or owner-scoping, that's IDOR — the single most common Laravel access-control bug.
  • `Model::find($request->id)` / `findOrFail($id)` then mutate / return, with no policy call and no where('user_id', ...) / relationship scoping → finding, severity by what the model's owner key and relationships verify.
  • Actor-selected target from request input (IDOR on write — the worst case). When the record to *write* is chosen by an id from the request body / query (User::findOrFail($request->input('user_id'))->update(...)) with no ownership check, that's a confirmed cross-account write: structural evidence even without route-model binding — the attacker names the victim directly. Do not soften it to "verify".
  • Scoped bindings count: Route::scopeBindings() or a nested resource scoping the child to the parent (users.posts resolving $post through $user->posts()) *is* object scoping — credit it.
  • Mass-assignment adjacency: $model->update($request->all()) where $fillable includes an ownership / role key (user_id, team_id, is_admin) is privilege escalation even when the row was scoped — note as a related finding.

To judge "should this be scoped?", look for ownership signals: user_id / team_id / tenant_id columns, belongsTo(User::class), a global scope, or the user's relationship methods. If you can't establish the model is owned, the finding is Moderate and phrased as "verify", not asserted as a hole.

> Tenancy comes from the project manifest. Read tenancy through > commands/_shared/read-manifest.sh (@rules/general/general.md *Project manifest*). > When it is database, each tenant owns its own database, and the tenant connection is > the tenant boundary. A model on the tenant connection is scoped by that connection, so a > missing tenant where (tenant_id, account_id) on it is not IDOR — do not report it.

Preview shortened. The full SKILL.md is in the pack.