laravel-security

Implements Laravel security practices for authentication, validation, CSRF, uploads, and rate limiting.

Updated Mar 18, 2026
One-click install
npx skills add https://github.com/freedom909/real-estate-saas --skill laravel-security-freedom909
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: laravel-security
Source: https://github.com/freedom909/real-estate-saas/tree/main/.trae/skills/laravel-security
Command: npx skills add https://github.com/freedom909/real-estate-saas --skill laravel-security-freedom909

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Laravel applications are exposed to common vulnerabilities like SQL injection, XSS, CSRF, mass assignment, and insecure file uploads when developers skip hardening steps. This Skill provides concrete, code-level security guidance so you can protect auth flows, user input, secrets, and production deployments without researching each attack vector separately. ## Core Features & Use Cases - Authentication & Authorization: Configure Sanctum/Passport token auth, password hashing rules, policies, gates, and route-level can middleware. - Input & Upload Safety: Enforce Form Request validation, mass-assignment guards, MIME/size checks for uploads, and private disk storage. - Production Hardening: Apply security headers (CSP, HSTS, X-Frame-Options), CORS restrictions, rate limiting, signed URLs, encrypted casts, and PII-safe logging. - Use Case: When building a new API endpoint that accepts invoice PDF uploads, use this Skill to add an UploadInvoiceRequest with authorization and mimes:pdf validation, store files on a non-public disk, and protect the route with auth:sanctum plus a throttle limiter. ## Quick Start Review my Laravel controller and routes for security issues and add the missing validation, authorization, and rate limiting protections.

Frequently Asked Questions about laravel-security

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I secure Laravel API endpoints with authentication?▼

Use Laravel Sanctum or Passport middleware such as `auth:sanctum` on routes to require valid tokens. Prefer short-lived tokens with refresh flows, and revoke tokens on logout or account compromise.

How to prevent mass assignment vulnerabilities in Laravel?▼

Define `$fillable` or `$guarded` on every Eloquent model and never call `Model::unguard()`. Prefer DTOs or explicit attribute mapping so request payloads cannot set derived or sensitive fields.

Does Laravel Sanctum support SPA authentication with CSRF?▼

Yes, Sanctum supports stateful SPA authentication using cookies. Configure your frontend domains in the `stateful` key of `config/sanctum.php` and keep the `VerifyCsrfToken` middleware enabled for XSRF protection.

How do I validate file uploads securely in Laravel?▼

Create a Form Request that checks authorization and validates file size, MIME type, and extension, such as `mimes:pdf` with a `max:5120` limit. Store uploads on a non-public disk and scan for malware when required.

Why should Laravel rate limiting be stricter on login routes?▼

Login, password reset, and OTP endpoints are prime targets for brute-force abuse. Define a named limiter with `RateLimiter::for('login')` using per-IP and per-email limits, then apply the `throttle` middleware to those routes.