laravel-security

Implements Laravel security practices for authentication, authorization, CSRF, XSS, and API protection.

5|15|Updated Jul 8, 2026
One-click install
npx skills add https://github.com/clfigueiredo/hermes-infra-skills --skill laravel-security-clfigueiredo
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: laravel-security
Source: https://github.com/clfigueiredo/hermes-infra-skills/tree/main/.hermes/skills/curso-hermes/laravel-security
Command: npx skills add https://github.com/clfigueiredo/hermes-infra-skills --skill laravel-security-clfigueiredo

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Laravel applications are frequently exposed to common vulnerabilities such as mass assignment, SQL injection, XSS, weak session handling, and misconfigured production settings. This Skill provides concrete, code-level security guidance so developers can harden Laravel apps against these threats without researching each attack vector from scratch. ## Core Features & Use Cases - Authentication & Authorization: Secure patterns for Sanctum and Passport token abilities, Gates, Policies, role middleware, password hashing, and session regeneration. - Injection & XSS Prevention: Safe Eloquent and Query Builder usage, Blade escaping rules, HTMLPurifier sanitization, and security headers middleware (CSP, X-Frame-Options). - Production Hardening: HTTPS enforcement, CSRF configuration, rate limiting, file upload validation, encrypted queue jobs, dependency auditing, and a security event logging channel. - Use Case: Before deploying a Laravel API to production, use this Skill to review your Sanctum token scopes, verify APP_DEBUG is false, add rate limiters to auth routes, and confirm mass assignment is restricted via $fillable. ## Quick Start Review my Laravel application for security vulnerabilities and apply the recommended fixes for authentication, validation, and production configuration.

Frequently Asked Questions about laravel-security

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

FAQPage Schema
How do I secure a Laravel API with Sanctum?▼

Issue tokens with specific abilities using $user->createToken('name', ['posts:read']), then protect routes with the auth:sanctum middleware and abilities:posts:read checks. Set a token expiration in config/sanctum.php and restrict stateful domains to your own hosts.

How do I prevent mass assignment vulnerabilities in Laravel?▼

Define a $fillable whitelist on each model and never use $guarded = []. Create records only from validated data via $request->validated() or $request->safe()->only([...]), and never pass $request->all() to create() or update().

Sanctum vs Passport: which should I use for Laravel API authentication?▼

Sanctum is recommended for most apps, including SPAs and simple token-based APIs, because it is lightweight and first-party. Passport is appropriate when you need full OAuth2 flows for third-party clients or complex authorization grants.

How do I prevent XSS in Laravel Blade templates?▼

Use {{ }} escaped output for all user input and reserve {!! !!} only for trusted, server-controlled HTML. For user-supplied HTML, purify it with HTMLPurifier using a whitelist of allowed tags, and use @js or @json when embedding data in JavaScript.

What production security settings does Laravel require?▼

Set APP_DEBUG=false, generate APP_KEY with php artisan key:generate, enforce HTTPS via middleware or URL::forceScheme, use secure and http_only session cookies, and add security headers like CSP and X-Frame-Options. Run composer audit in CI to catch vulnerable dependencies.

Why is my Laravel CSRF token mismatch error happening?▼

CSRF errors occur when forms lack the @csrf directive or AJAX requests omit the X-CSRF-TOKEN header from the csrf-token meta tag. Only exclude routes in VerifyCsrfToken when they have their own verification, such as Stripe webhook signatures.