gpt4 book ai didi

Laravel- VerifyCsrfToken 排除不工作

转载 作者:行者123 更新时间:2023-12-04 01:25:18 28 4
gpt4 key购买 nike

我在从验证 CSRF token 中排除路由时遇到问题。

我试图排除我称为 mydomain.com/example 的端点上的所有请求,所以我在 VerifyCsrfToken.php 文件中这样做。

class VerifyCsrfToken extends Middleware
{
/**
* Indicates whether the XSRF-TOKEN cookie should be set on the response.
*
* @var bool
*/
protected $addHttpCookie = true;

/**
* The URIs that should be excluded from CSRF verification.
*
* @var array
*/
protected $except = [
'example/*',
];
}

但这并没有解决问题。如果我在 app/Http/Kernel.php 文件中执行此操作,则一切正常。

有谁知道为什么我不能排除特定路线?

protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
// \Illuminate\Session\Middleware\AuthenticateSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
//\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
\Barryvdh\Cors\HandleCors::class,
],

'api' => [
'throttle:60,1',
'bindings',
],
];

最佳答案

您通过使用通配符排除了每条路由AFTER“/example”,并且中间件未在内核中注册,因此甚至没有运行

protected $except = [
'/example'
];

不要忘记取消中间件的注释

'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
// \Illuminate\Session\Middleware\AuthenticateSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class, // <--- HERE
\Illuminate\Routing\Middleware\SubstituteBindings::class,
\Barryvdh\Cors\HandleCors::class,
],

关于Laravel- VerifyCsrfToken 排除不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62045783/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com