laravel-gate-audit
Skill0 starsChanged 3 months agoMITView on GitHub
Use this skill when auditing a Laravel application for authorization gate and policy usage, especially requests like "find missing gates", "audit Gate::allows", "check @can permissions", "verify policies", or "find undefined abilities". It traces ability usage across controllers, models, Blade, Livewire, routes, jobs, tests, and middleware, then compares each usage against Gate::define declarations, policy methods, policy mappings, and before/after hooks to report missing or suspicious definitions.
In this repository7 other files it gives its agents.
- australian-englishSkill
- campaign-copywriterSkill
- dot-productSkill
- human-copy-styleSkill
- marketing-strategistSkill
- portfolio-copywriterSkill
- yuma-it-contextSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
14 rules. About 0 are common, 7 are distinctive, and 7 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈7
Distinctive · estimate
This author's own choices. Worth a look.
7
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 10
Write the audit report in Australian English.
- Very specific: line 40
Use Grep/Glob first when available.
- Very specific: line 54
If the repo has large generated or vendor folders, exclude them with -g '!vendor/', -g '!storage/', or project-specific generated paths.
- Very specific: line 63
Treat policy before methods and Gate::before hooks as broad allow/deny hooks, not as proof that every named ability is intentionally …
- Very specific: line 64
Treat dynamic ability names such as $user->can($ability, $model) as uncertain unless the variable can be resolved locally or from a …
- Distinctive: line 65
Check enum or constant-backed abilities before declaring a string missing.
- Very specific: line 66
If Laravel auto-discovery is in use, a model App\Models\Post can resolve to App\Policies\PostPolicy without an explicit $policies entry.
- Distinctive: line 71
Start with a short summary and counts:
- Very specific: line 84
call style, for example Gate::allows, @can, can: middleware, or $this->authorize
- Distinctive: line 131
Before finalising the audit:
- Distinctive: line 135
If tests exist for authorization, identify the relevant test command but do not claim a missing definition is fixed unless the user asked …
- Distinctive: line 140
Do not use this for a general Laravel security audit unless the task specifically includes gates, policies, abilities, permissions, or …
- Distinctive: line 141
Do not use this for authentication issues such as login, guards, sessions, password reset, Sanctum tokens, or OAuth unless they interact …
- Distinctive: line 142
Do not use this for database role/permission modelling alone unless the request asks whether those permissions are wired into Laravel …
≈ “Common” is an estimate: at least 1 in 5 of the 364,980 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Laravel Gate Audit
Audit Laravel authorization usage by comparing every referenced ability with the places Laravel can define or resolve that ability. The goal is to find missing definitions, typo-level mismatches, stale checks, and checks that rely on implicit policies without enough evidence.
Write the audit report in Australian English. Defer spelling detail to the australian-english skill; leave code identifiers, ability strings, class names, and file paths spelled exactly as they appear in the codebase.
Audit Scope
Inspect gate and policy ability usage in:
- controllers, form requests, actions, services, jobs, listeners, middleware, commands, models, and tests
- Blade directives such as
@can,@cannot,@canany,@elsecan, and@elsecannot - code calls such as
Gate::allows,Gate::denies,Gate::check,Gate::authorize,Gate::inspect,Gate::any,Gate::none,can,cant,cannot,authorize,authorizeForUser, and route middleware usingcan: - Livewire, Inertia, Nova, Filament, API resource, or package-specific authorization wrappers when present
Inspect gate and policy definitions in:
Gate::define,Gate::resource,Gate::before, andGate::afterAuthServiceProvider, custom service providers, route/service bootstrapping files, and package providers- policy classes under
app/Policiesor project-specific policy directories - policy mappings in
Gate::policy,$policies, service providers, package config, and auto-discovered policy names - policy methods including
viewAny,view,create,update,delete,restore,forceDelete, and custom ability methods
Working Method
- Identify the Laravel version and project shape. Check
composer.json,app/Providers,bootstrap/app.php,routes/,app/Policies, and test folders. - Build an ability usage inventory. Record the ability string, file, line, call style, subject/model argument when available, and any user override.
- Build a definition inventory. Record explicit gates, resource gates, policy mappings, policy class methods, global hooks, and package-provided definitions.
- Match each usage to a definition using Laravel's resolution rules, not just string equality.
- Report definite missing definitions separately from uncertain or dynamic cases.
- Include enough evidence for each finding: file path, line number, ability, subject/model, expected definition location, and why it appears missing.
Search Commands
Use Grep/Glob first when available. When shell search is more efficient, run ripgrep from the repo root.
Find common ability usages:
rg -n "Gate::(allows|denies|authorize|inspect|any|none|check)|->(can|cant|cannot)\(|\b(can|cant|cannot)\(|\$this->authorize\(|authorizeForUser\(|@can\b|@cannot\b|@canany\b|@elsecan\b|@elsecannot\b|can:" . -g "*.php" -g "*.blade.php"Find definitions and policy wiring:
rg -n "Gate::(define|resource|policy|before|after)|protected \$policies|class .*Policy|function (viewAny|view|create|update|delete|restore|forceDelete|before|after)\b" . -g "*.php"If the repo has large generated or vendor folders, exclude them with -g '!vendor/**', -g '!storage/**', or project-specific generated paths.
Matching Rules
- For
Gate::define('ability', ...), match the exact ability string. - For
Gate::resource('posts', PostPolicy::class), expand the generated ability names before reporting anything missing. - For
$user->can('update', $post),$this->authorize('update', $post), and route middleware likecan:update,post, matchupdateagainst the policy resolved for the subject model. - For
@can('update', $post), match like$user->can('update', $post). - For
@can('manage-users')orGate::allows('manage-users')without a model argument, expect an explicit gate unless the project has a documented convention that maps string abilities elsewhere. - Treat policy
beforemethods andGate::beforehooks as broad allow/deny hooks, not as proof that every named ability is intentionally defined. - Treat dynamic ability names such as
$user->can($ability, $model)as uncertain unless the variable can be resolved locally or from a constant/enum. - Check enum or constant-backed abilities before declaring a string missing. Search for the enum case or constant value and its consumers.
- If Laravel auto-discovery is in use, a model
App\Models\Postcan resolve toApp\Policies\PostPolicywithout an explicit$policiesentry. Verify class existence and method names. - For
authorizeResource, inspect the controller model and compare the generated controller abilities against the target policy methods.
Report Format
Start with a short summary and counts:
- total ability usages found
- definite missing definitions
- suspicious mismatches
- dynamic or unresolved usages
Then list findings by severity: missing definitions first, then suspicious mismatches, then dynamic unresolved usages.
For each finding include:
file:line- ability name
- call style, for example
Gate::allows,@can,can:middleware, or$this->authorize - subject/model argument if present
- expected definition, for example
Gate::define('publish posts')orPostPolicy::publish - evidence checked, for example searched providers, policy mappings, and policy class methods
- suggested minimal fix
Use these categories:
- Missing definition: ability has no explicit gate and no resolvable policy method.
- Suspicious mismatch: likely typo, wrong subject model, pluralisation mismatch, or policy method name mismatch.
- Dynamic unresolved: ability is variable-driven and cannot be proven from static search.
- Covered: optional section for important abilities that are correctly defined.
Example finding
Missing definition —
app/Http/Controllers/PostController.php:48
- ability:
publish- call style:
$this->authorize('publish', $post)- subject:
App\Models\Post- expected definition:
App\Policies\PostPolicy::publish- evidence checked:
PostPolicyexists and resolves forPostvia auto-discovery but has nopublishmethod; noGate::define('publish', ...)in any registered provider; nobeforehook grants it for normal users- suggested fix: add
public function publish(User $user, Post $post): booltoPostPolicy
Common Laravel Edge Cases
Laravel 11+ provider layout
Laravel 11 apps may not have the older app/Providers/AuthServiceProvider.php. Check bootstrap/app.php, AppServiceProvider, package providers, and any provider registered in bootstrap/providers.php before reporting missing gates.
Policy auto-discovery
Laravel can discover policies by naming convention. Do not require $policies mappings when the policy class exists in the expected namespace and contains the needed method.
Resource gates and controllers
Gate::resource and controller authorizeResource both expand into multiple abilities. Expand them before matching so generated abilities are not falsely reported as missing.
Super-admin hooks
Global Gate::before or policy before methods can short-circuit authorization for privileged users. They do not replace ability definitions for normal users, so still report missing explicit gates or policy methods.
Package permissions
Projects using packages such as Spatie Permission often check permissions through gates or can middleware. Verify whether package service providers register those permissions as gates before marking them missing.
Verification
Before finalising the audit:
- Re-run the usage and definition searches after expanding non-standard folders.
- Spot-check at least one finding from each category by reading the surrounding code.
- If tests exist for authorization, identify the relevant test command but do not claim a missing definition is fixed unless the user asked you to change code and tests pass.
- Make clear which findings are static-analysis confidence and which need runtime confirmation.
When NOT To Use
- Do not use this for a general Laravel security audit unless the task specifically includes gates, policies, abilities, permissions, or authorization checks.
- Do not use this for authentication issues such as login, guards, sessions, password reset, Sanctum tokens, or OAuth unless they interact with gate/policy checks.
- Do not use this for database role/permission modelling alone unless the request asks whether those permissions are wired into Laravel authorization.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

