Skip to content
Back to skills

Request Forgery Protection

ASecurity

Configure CSRF and origin-aware request forgery protection; PreventRequestForgery middleware (Laravel 13+) with token fallback and exclusions

  • 147 stars
  • 0 votes
  • 0 copies
  • 4 views
  • Added September 6, 2026
testingphptesting

Works with

  • cli

Security analysis

A100/100

Scanned September 6, 2026

npx -y skills add jpcaparas/superpowers-laravel --skill request-forgery-protection --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Request Forgery Protection?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Request Forgery Protection
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/jpcaparas-request-forgery-protection/badge)](https://www.skillsdirectory.com/skills/jpcaparas-request-forgery-protection)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: laravel:request-forgery-protection
description: Configure CSRF and origin-aware request forgery protection; PreventRequestForgery middleware (Laravel 13+) with token fallback and exclusions
---

# Request Forgery Protection

Protect state-changing routes from cross-site request forgery. Laravel 13 formalizes this as `PreventRequestForgery`, adding origin-aware verification (`Sec-Fetch-Site`) on top of token-based CSRF.

## Commands

```
# Blade forms still emit tokens
<form method="POST" action="/profile">
    @csrf
    ...
</form>

# Laravel 13+: reference the new middleware class
use Illuminate\Foundation\Http\Middleware\PreventRequestForgery;   // was: VerifyCsrfToken

->withoutMiddleware([PreventRequestForgery::class]);

# Optional origin-only mode (bootstrap/app.php)
->withMiddleware(function (Middleware $middleware) {
    $middleware->preventRequestForgery(originOnly: true);
})

# Exclude webhook URIs from verification
$middleware->validateCsrfTokens(except: ['stripe/*']);
```

## Patterns

- Keep `@csrf` in forms; origin verification is additive, token fallback covers older browsers/HTTP
- Only enable `originOnly` when all clients are modern browsers over HTTPS
- Exclude third-party webhook endpoints explicitly and verify their signatures instead
- When upgrading to 13.x, replace `VerifyCsrfToken` references with `PreventRequestForgery` (old name remains a deprecated alias)
- Never disable forgery protection globally to "fix" a failing integration — scope exclusions per URI

## Testing

- Feature tests bypass CSRF by default; add explicit tests for excluded webhook routes and their signature checks
- Assert 419 responses for missing/invalid tokens where relevant

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.