laravel-security
Skill1 starsChanged 7 months agoMITView on GitHub
Laravel security best practices for authn/authz, validation, CSRF, mass assignment, file uploads, secrets, rate limiting, and secure deployment.
19 other projects use a version of this, 2 of them edited.
Adopted by
Most recently taken up by
- cindovahq/security-skillstheir own version, first seen Nov 8, 2026
- renepf/claude-skillstheir own version, first seen Oct 25, 2026
- davidanthonyn/claude-skillsword for word, first seen Oct 20, 2026
- STIFLEUR390/agent-skillstheir own version, first seen Oct 16, 2026
- ashrafiucse/security-audit-skillstheir own version, first seen Oct 13, 2026
- gongyijie85/dsh-ecctheir own version, first seen Oct 13, 2026
Used with
Projects with it also use skill-creator.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
SentrySkillskill-creator
Create new agent skills following the Agent Skills specification. Use when asked to "create a skill", "add a new skill", "write a skill", "make a skill", "build a skill", or scaffold a new skill with SKILL.md. Guides through requirements, writing, registration, and verification.
Also in 4 projects that use this
Other versions19 projects use a version of this.
Word for word · 7
- loulanyue/awesome-claude-notes★ 272100% same
- PUPT-Quantum-Leap/capstone-nlcom-volunteer-management-system★ 4100% same
- junimnjw/everything-claude-code★ 1100% same
- TironFox/everything-claude-code★ 1100% same
- davidanthonyn/claude-skills★ 0100% same
- MohamedEssam0-0/claude-skills★ 0100% same
- PeterYang888/claude-skills★ 0100% same
Edited · 2
- Fmarzochi/EGC★ 6199% same
- ronmkr/PromptBook★ 299% same
Wrote their own version · 10
- pekral/cursor-rules★ 10same name
- gongyijie85/dsh-ecc★ 8same name
- ashrafiucse/security-audit-skills★ 2same name
- wakqasahmed/skills★ 2same name
- NISTALTALSON/essential-claude-skills★ 1same name
- romaintoso78/claude-skills★ 1same name
- SamuelNDCE/claude-super-skill-library★ 1same name
- cindovahq/security-skills★ 0same name
- renepf/claude-skills★ 0same name
- STIFLEUR390/agent-skills★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository269 other files it gives its agents.
- AGENTS.mdAGENTS.md
- .codex/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- examples/CLAUDE.mdCLAUDE.md
- .cursor/rules/common-agents.mdCursor rule
- .cursor/rules/common-coding-style.mdCursor rule
- .cursor/rules/common-development-workflow.mdCursor rule
- .cursor/rules/common-git-workflow.mdCursor rule
- .cursor/rules/common-hooks.mdCursor rule
- .cursor/rules/common-patterns.mdCursor rule
- .cursor/rules/common-performance.mdCursor rule
- .cursor/rules/common-security.mdCursor rule
- .cursor/rules/common-testing.mdCursor rule
- .cursor/rules/golang-coding-style.mdCursor rule
- .cursor/rules/golang-hooks.mdCursor rule
- .cursor/rules/golang-patterns.mdCursor rule
- .cursor/rules/golang-security.mdCursor rule
- .cursor/rules/golang-testing.mdCursor rule
- .cursor/rules/kotlin-coding-style.mdCursor rule
- .cursor/rules/kotlin-hooks.mdCursor rule
- .cursor/rules/kotlin-patterns.mdCursor rule
- .cursor/rules/kotlin-security.mdCursor rule
- .cursor/rules/kotlin-testing.mdCursor rule
- .cursor/rules/php-coding-style.mdCursor rule
- .cursor/rules/php-hooks.mdCursor rule
- .cursor/rules/php-patterns.mdCursor rule
- .cursor/rules/php-security.mdCursor rule
- .cursor/rules/php-testing.mdCursor rule
- .cursor/rules/python-coding-style.mdCursor rule
- .cursor/rules/python-hooks.mdCursor rule
- .cursor/rules/python-patterns.mdCursor rule
- .cursor/rules/python-security.mdCursor rule
- .cursor/rules/python-testing.mdCursor rule
- .cursor/rules/swift-coding-style.mdCursor rule
- .cursor/rules/swift-hooks.mdCursor rule
- .cursor/rules/swift-patterns.mdCursor rule
- .cursor/rules/swift-security.mdCursor rule
- .cursor/rules/swift-testing.mdCursor rule
- .cursor/rules/typescript-coding-style.mdCursor rule
- .cursor/rules/typescript-hooks.mdCursor rule
- .cursor/rules/typescript-patterns.mdCursor rule
- .cursor/rules/typescript-security.mdCursor rule
- .cursor/rules/typescript-testing.mdCursor rule
- agent-introspection-debuggingSkill
- agent-sortSkill
- api-designSkill
- article-writingSkill
- backend-patternsSkill
- brand-voiceSkill
- bun-runtimeSkill
- claude-apiSkill
- coding-standardsSkill
- content-engineSkill
- crosspostSkill
- deep-researchSkill
- dmux-workflowsSkill
- documentation-lookupSkill
- e2e-testingSkill
- eval-harnessSkill
- everything-claude-code-conventionsSkill
- The first 60 shown.
The file
Show its rules and text
We split this skill into the rules it gives an agent
24 rules. 0 are common, 20 are distinctive, and 4 are very specific to this project.
0
Common
Most of the 6 edited versions we read keep these.
20
Distinctive
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- could be automatic: a setting could enforce it
- Very specific: line 37
Use SESSION_SAME_SITE=strict for high-risk flows
- Distinctive: line 42
Use Laravel Sanctum or Passport for API auth
- Distinctive: line 43
Prefer short-lived tokens with refresh flows for sensitive data
- Distinctive: line 60
Use Laravel's password broker for reset flows
- Distinctive: line 75
Use policies for model-level authorization
- Distinctive: line 82
Use policy middleware for route-level enforcement:
- Distinctive: line 93
Always validate inputs with Form Requests
- Distinctive: line 94
Use strict validation rules and type checks
- Distinctive: line 95
Never trust request payloads for derived fields
- Very specific: line 99
Use $fillable or $guarded and avoid Model::unguard()
- Distinctive: line 100
Prefer DTOs or explicit attribute mapping
- Distinctive: line 104
Use Eloquent or query builder parameter binding
- Distinctive: line 105
Avoid raw SQL unless strictly necessary
- Very specific: line 114
Use {!! !!} only for trusted, sanitized HTML
- Very specific: line 119
Keep VerifyCsrfToken middleware enabled
- Distinctive: line 162
Use stricter limits for login, password reset, and OTP
- Distinctive: line 179
Never commit secrets to source control
- Distinctive: line 180
Use environment variables and secret managers
- Distinctive: line 185
Use encrypted casts for sensitive columns at rest.
- Distinctive: line 195
Add CSP, HSTS, and frame protection where appropriate
- Distinctive: line 196
Use trusted proxy configuration to enforce HTTPS redirects
- Distinctive: line 226
Avoid wildcard origins for authenticated routes
- Distinctive: line 247
Never log passwords, tokens, or full card data
- Distinctive: line 267
Use signed routes for temporary, tamper-proof links.
“Common” is measured: kept by at least 6 in 10 of the 6 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Laravel Security Best Practices
Comprehensive security guidance for Laravel applications to protect against common vulnerabilities.
When to Activate
- Adding authentication or authorization
- Handling user input and file uploads
- Building new API endpoints
- Managing secrets and environment settings
- Hardening production deployments
How It Works
- Middleware provides baseline protections (CSRF via
VerifyCsrfToken, security headers viaSecurityHeaders). - Guards and policies enforce access control (
auth:sanctum,$this->authorize, policy middleware). - Form Requests validate and shape input (
UploadInvoiceRequest) before it reaches services. - Rate limiting adds abuse protection (
RateLimiter::for('login')) alongside auth controls. - Data safety comes from encrypted casts, mass-assignment guards, and signed routes (
URL::temporarySignedRoute+signedmiddleware).
Core Security Settings
APP_DEBUG=falsein productionAPP_KEYmust be set and rotated on compromise- Set
SESSION_SECURE_COOKIE=trueandSESSION_SAME_SITE=lax(orstrictfor sensitive apps) - Configure trusted proxies for correct HTTPS detection
Session and Cookie Hardening
- Set
SESSION_HTTP_ONLY=trueto prevent JavaScript access - Use
SESSION_SAME_SITE=strictfor high-risk flows - Regenerate sessions on login and privilege changes
Authentication and Tokens
- Use Laravel Sanctum or Passport for API auth
- Prefer short-lived tokens with refresh flows for sensitive data
- Revoke tokens on logout and compromised accounts
Example route protection:
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
Route::middleware('auth:sanctum')->get('/me', function (Request $request) {
return $request->user();
});Password Security
- Hash passwords with
Hash::make()and never store plaintext - Use Laravel's password broker for reset flows
use Illuminate\Support\Facades\Hash;
use Illuminate\Validation\Rules\Password;
$validated = $request->validate([
'password' => ['required', 'string', Password::min(12)->letters()->mixedCase()->numbers()->symbols()],
]);
$user->update(['password' => Hash::make($validated['password'])]);Authorization: Policies and Gates
- Use policies for model-level authorization
- Enforce authorization in controllers and services
$this->authorize('update', $project);Use policy middleware for route-level enforcement:
use Illuminate\Support\Facades\Route;
Route::put('/projects/{project}', [ProjectController::class, 'update'])
->middleware(['auth:sanctum', 'can:update,project']);Validation and Data Sanitization
- Always validate inputs with Form Requests
- Use strict validation rules and type checks
- Never trust request payloads for derived fields
Mass Assignment Protection
- Use
$fillableor$guardedand avoidModel::unguard() - Prefer DTOs or explicit attribute mapping
SQL Injection Prevention
- Use Eloquent or query builder parameter binding
- Avoid raw SQL unless strictly necessary
DB::select('select * from users where email = ?', [$email]);XSS Prevention
- Blade escapes output by default (
{{ }}) - Use
{!! !!}only for trusted, sanitized HTML - Sanitize rich text with a dedicated library
CSRF Protection
- Keep
VerifyCsrfTokenmiddleware enabled - Include
@csrfin forms and send XSRF tokens for SPA requests
For SPA authentication with Sanctum, ensure stateful requests are configured:
// config/sanctum.php
'stateful' => explode(',', env('SANCTUM_STATEFUL_DOMAINS', 'localhost')),File Upload Safety
- Validate file size, MIME type, and extension
- Store uploads outside the public path when possible
- Scan files for malware if required
final class UploadInvoiceRequest extends FormRequest
{
public function authorize(): bool
{
return (bool) $this->user()?->can('upload-invoice');
}
public function rules(): array
{
return [
'invoice' => ['required', 'file', 'mimes:pdf', 'max:5120'],
];
}
}$path = $request->file('invoice')->store(
'invoices',
config('filesystems.private_disk', 'local') // set this to a non-public disk
);Rate Limiting
- Apply
throttlemiddleware on auth and write endpoints - Use stricter limits for login, password reset, and OTP
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\RateLimiter;
RateLimiter::for('login', function (Request $request) {
return [
Limit::perMinute(5)->by($request->ip()),
Limit::perMinute(5)->by(strtolower((string) $request->input('email'))),
];
});Secrets and Credentials
- Never commit secrets to source control
- Use environment variables and secret managers
- Rotate keys after exposure and invalidate sessions
Encrypted Attributes
Use encrypted casts for sensitive columns at rest.
protected $casts = [
'api_token' => 'encrypted',
];Security Headers
- Add CSP, HSTS, and frame protection where appropriate
- Use trusted proxy configuration to enforce HTTPS redirects
Example middleware to set headers:
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
final class SecurityHeaders
{
public function handle(Request $request, \Closure $next): Response
{
$response = $next($request);
$response->headers->add([
'Content-Security-Policy' => "default-src 'self'",
'Strict-Transport-Security' => 'max-age=31536000', // add includeSubDomains/preload only when all subdomains are HTTPS
'X-Frame-Options' => 'DENY',
'X-Content-Type-Options' => 'nosniff',
'Referrer-Policy' => 'no-referrer',
]);
return $response;
}
}CORS and API Exposure
- Restrict origins in
config/cors.php - Avoid wildcard origins for authenticated routes
// config/cors.php
return [
'paths' => ['api/*', 'sanctum/csrf-cookie'],
'allowed_methods' => ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'],
'allowed_origins' => ['https://app.example.com'],
'allowed_headers' => [
'Content-Type',
'Authorization',
'X-Requested-With',
'X-XSRF-TOKEN',
'X-CSRF-TOKEN',
],
'supports_credentials' => true,
];Logging and PII
- Never log passwords, tokens, or full card data
- Redact sensitive fields in structured logs
use Illuminate\Support\Facades\Log;
Log::info('User updated profile', [
'user_id' => $user->id,
'email' => '[REDACTED]',
'token' => '[REDACTED]',
]);Dependency Security
- Run
composer auditregularly - Pin dependencies with care and update promptly on CVEs
Signed URLs
Use signed routes for temporary, tamper-proof links.
use Illuminate\Support\Facades\URL;
$url = URL::temporarySignedRoute(
'downloads.invoice',
now()->addMinutes(15),
['invoice' => $invoice->id]
);use Illuminate\Support\Facades\Route;
Route::get('/invoices/{invoice}/download', [InvoiceController::class, 'download'])
->name('downloads.invoice')
->middleware('signed');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.

