csrf handling mit der korrekten middleware verbunden

This commit is contained in:
Codex Agent
2025-12-23 09:54:26 +01:00
parent 826e2a93ce
commit ed5c1918fc
3 changed files with 10 additions and 3 deletions

View File

@@ -56,7 +56,9 @@ class Handler extends ExceptionHandler
public function render($request, Throwable $e)
{
if ($e instanceof TokenMismatchException) {
$this->logCsrfMismatch($request);
$this->logCsrfMismatch($request, 'token_mismatch');
} elseif ($e instanceof HttpExceptionInterface && $e->getStatusCode() === 419) {
$this->logCsrfMismatch($request, 'http_419');
}
if ($request->expectsJson()) {
@@ -251,13 +253,14 @@ class Handler extends ExceptionHandler
return $throwable instanceof $className;
}
private function logCsrfMismatch($request): void
private function logCsrfMismatch($request, string $reason): void
{
if (! app()->environment('development')) {
return;
}
Log::warning('[CSRF] Token mismatch', [
'reason' => $reason,
'method' => $request->method(),
'path' => $request->path(),
'full_url' => $request->fullUrl(),

View File

@@ -64,6 +64,10 @@ return Application::configure(basePath: dirname(__DIR__))
]);
$middleware->encryptCookies(except: ['appearance', 'sidebar_state']);
$middleware->validateCsrfTokens(except: [
'paddle/webhook',
'paddle/webhook*',
]);
$middleware->web(append: [
\App\Http\Middleware\SetLocale::class,

View File

@@ -377,6 +377,6 @@ Route::middleware('auth')->group(function () {
});
Route::post('/paddle/webhook', [PaddleWebhookController::class, 'handle'])
->withoutMiddleware([\App\Http\Middleware\VerifyCsrfToken::class])
->withoutMiddleware([\Illuminate\Foundation\Http\Middleware\ValidateCsrfToken::class])
->middleware('throttle:paddle-webhook')
->name('paddle.webhook');