问题描述
我需要重写VerifyCsrftoken
类的tokensMatch
方法,以便在比较令牌之前清除掉令牌上残留的一些奇怪的字符串伪像,例如:
<?PHP
namespace App\Http\Middleware;
use Illuminate\Foundation\Http\Middleware\VerifyCsrftoken as Middleware;
class VerifyCsrftoken extends Middleware
{
/**
* The URIs that should be excluded from CSRF verification.
*
* @var array
*/
protected $except = [
//
];
protected function tokensMatch($request)
{
$token = $this->getTokenFromrequest($request);
// Check if token still has cookie prefix? Strip it off.
if (strpos($token,'|') !== false) {
$token = explode('|',$this->getTokenFromrequest($request))[1];
}
// Check for random '";' on the end of the token? Strip it off.
if (strpos($token,'";') !== false) {
$token = str_replace('";','',$token);
}
return is_string($request->session()->token()) &&
is_string($token) &&
hash_equals($request->session()->token(),$token);
}
}
通过调试,我注意到来自$token
函数的getTokenFromrequest
看起来像这样:
fc1e5|MVz88AWCnGydS4nuZXjAlpaYTBKkLtuqsXAUlhc9";
来自$request->session()->token()
的令牌看起来像这样:
MVz88AWCnGydS4nuZXjAlpaYTBKkLtuqsXAUlhc9
请注意,除了第一个前缀以竖线分隔的前缀和双引号结尾(以分号结尾)之外,它们是如何相同的?
我的项目是一个Laravel 5.5项目,该项目已更新至7.x,并且全新安装了Sanctum。
有什么想法吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)