laravel-auth-hardening
Skill4 starsChanged 5 months agoMITView on GitHub
Laravel authentication hardening patterns — anti-enumeration on auth-adjacent endpoints, role allowlist discipline, Sanctum token revocation test patterns, null-safe ownership comparisons in policies, and vulnerability-class thinking. Use when implementing or auditing Laravel auth, Sanctum logout, password reset, OTP resend, registration, or policy-based authorization. Call for Laravel security review, auth hardening, or closing enumeration and role-bypass audit findings.
In this repository101 other files it gives its agents.
- ai-video-understandingSkill
- apple-foundation-modelsSkill
- arch-dddSkill
- arch-decision-recordsSkill
- arch-diagramsSkill
- arch-eventsSkill
- arch-mvp-roadmapSkill
- arch-python-modernSkill
- aws-app-runnerSkill
- aws-cicd-patternsSkill
- aws-security-hardeningSkill
- azure-functions-python-v2Skill
- azure-identity-m2m-authSkill
- azure-service-bus-messagingSkill
- azure-workflow-execution-modelsSkill
- caddy-tls-proxySkill
- compliance-frameworksSkill
- design-system-workflowSkill
- dev-debugging-strategiesSkill
- dev-standardsSkill
- docker-python-poetrySkill
- docker-pythonSkill
- fastapi-patternsSkill
- ffmpeg-laravel-videoSkill
- formik-yup-react-nativeSkill
- frontend-accessibilitySkill
- frontend-angular-aiSkill
- frontend-angularSkill
- frontend-angular-toolingSkill
- frontend-design-systemsSkill
- frontend-material-chatSkill
- frontend-material-design-3Skill
- frontend-svelteSkill
- gcp-cicd-patternsSkill
- gcp-cloud-runSkill
- gcp-cloudsql-infrastructureSkill
- gcp-finopsSkill
- gcp-observabilitySkill
- gcp-security-hardeningSkill
- github-actions-cicdSkill
- healthkit-biofeedbackSkill
- infra-terraformSkill
- ios-app-qualitySkill
- ios-audio-hapticsSkill
- jest-nestjs-testingSkill
- langchain-azure-openai-patternsSkill
- laravel-ci-mysqlSkill
- laravel-mix-webpackSkill
- laravel-modern-patternsSkill
- laravel-pint-patternsSkill
- laravel-s3-storageSkill
- laravel-sail-dockerSkill
- mobile-app-deploymentSkill
- mobile-e2e-testingSkill
- mobile-offline-syncSkill
- mobile-push-notificationsSkill
- mobile-video-uploadSkill
- mongodb-asyncmongoclient-patternsSkill
- mongodb-atlas-patternsSkill
- nestjs-patternsSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 2 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 27
When an audit names ONE endpoint with an enumeration vulnerability, grep all controllers for the pattern and fix the class.
- Very specific: line 35
When an audit closes one endpoint's role-write vulnerability, grep all controllers for 'role' => validation rules and $request->role writes.
- Distinctive: line 58
When an audit flags ONE instance of a pattern (role-write, enumeration, policy hole), the correct scope is every endpoint that shares the …
≈ “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 Auth Hardening
Targeted hardening patterns for Laravel authentication and authorization surfaces. Specializes laravel-modern-patterns on the security axis.
When to Use
- Closing audit findings on auth-adjacent endpoints (forgot-password, OTP resend, register)
- Implementing Sanctum logout or TTL expiry tests that actually exercise revocation
- Writing policy ownership comparisons on dual-key (UUID/integer) models
- Locking down role assignment to prevent unauthorized privilege escalation
- Treating a vulnerability as a class across all endpoints, not just the flagged one
Anti-Enumeration Pattern
Auth-adjacent endpoints that condition their response on email existence leak the existence of registered accounts. Returning distinct status codes (200 vs 404) on forgotPassword, resendOtp, register OTP failure paths all share this shape.
Pattern: return 200 with a generic message regardless of whether the email exists. Call the side-effect service (e.g., send email, create OTP) only when the user is found — the caller never observes the branch.
Timing parity is also required — a DB lookup for an existing user takes longer than an early-return, leaking existence via latency. See reference.md for the unconditional-dispatch mitigation.
When an audit names ONE endpoint with an enumeration vulnerability, grep all controllers for the pattern and fix the class. The resendOtp and register OTP failure paths were live alongside a flagged forgotPassword in practice because only the flagged endpoint was patched.
Role Allowlist Discipline
Role values accepted from public-facing request bodies are a privilege-escalation surface. Admin roles in public-facing validation rules open a privilege-escalation path — they belong in seeders, internal provisioning paths, or migrations.
Validation rules close the endpoint surface; if role remains in $fillable, any fill()/update() call elsewhere still writes it. Remove role from $fillable or route all role writes through a named setter (User::assignRole()). See reference.md for the pattern.
When an audit closes one endpoint's role-write vulnerability, grep all controllers for 'role' => validation rules and $request->role writes. Login, mobile-login, register, and complete-signup endpoints often share the same pattern across the same codebase.
Sanctum Revocation Test Pattern
actingAs($user, 'sanctum') injects a TransientToken, not an Eloquent PersonalAccessToken. The production revocation guard (instanceof Model) is never exercised — logout tests pass regardless of whether revocation works.
A genuine revocation test POSTs to /login, captures the specific token's id, POSTs to /logout, then asserts assertDatabaseMissing('personal_access_tokens', ['id' => $tokenId]). Row-count delta passes a broken implementation that deletes all tokens. The 401 assertion requires forgetGuards() first — the auth guard caches the user from login and masks revocation otherwise. TTL expiry tests need the same flush.
See reference.md for the full annotated test stub.
Null-Safe Ownership Comparisons
Policies that compare user identity to a relation's field should use null-safe navigation so a missing or unloaded relation returns false rather than throwing:
// Returns false on null property relation — no auth bypass via missing relation
return $user->uuid === $order->item?->owner_id;The ?-> operator returns null on a null relation, and null === uuid evaluates to false. Without it, accessing a field on a null relation throws, and error handlers may produce unexpected HTTP responses.
Vulnerability-Class Thinking
When an audit flags ONE instance of a pattern (role-write, enumeration, policy hole), the correct scope is every endpoint that shares the shape — not just the named one. Grep-driven class closure prevents the "closed the finding, left the class open" outcome.
Auth seam catalog for role-aware redirects: a role-based post-auth redirect added at one entry point (e.g. login) is incomplete until every token-issuing seam applies the same logic. Typical seams: email login, OTP→login, complete-signup (Google OAuth callback), social-success client handler, password reset. A layout guard partially masks misses (flash + redirect), but reviewers catch them. See reference.md for the seam catalog checklist.
Key References
laravel-modern-patterns— broad Sanctum + Eloquent + policy coverageunit-test-standards— general test anti-patterns including false-positive guards
See reference.md for the orphaned-route detection pattern and php artisan policy:list version-gap note.
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.

