Is there a case to keep "_token" as part of the request?
Once the VerifyCsrfToken middleware has executed, should the "_token" be removed? I'm just wondering if people still use it in their controllers or something else?
Should this line be added to the middleware?
$request->offsetUnset('_token');
So that the handle method becomes:
if (
$this->isReading($request) ||
$this->runningUnitTests() ||
$this->inExceptArray($request) ||
$this->tokensMatch($request)
) {
$request->offsetUnset('_token');
return tap($next($request), function ($response) use ($request) {
if ($this->shouldAddXsrfTokenCookie()) {
$this->addCookieToResponse($request, $response);
}
});
}
throw new TokenMismatchException;
@JLRDW - At the point where I added $request->offsetUnset('_token');, the token has already matched. So I was looking for feedback to see if the "_token" parameter is still useful afterwards.
@travisobregon you're safe to remove it but really you don't need to - you don't gain anything by removing it after it has been validated. If you want to get a request object without the token you can just use request()->except('_token') or better yet, use request()->only('fields', 'you', 'want').
@travisobregon@jlrdw sometimes thinks what he is saying makes sense.. but @billriess is right - u can ignore it or remove it if you so desire.. if you have fillables in your model then you can simply do Mode::create($request->all()) and everything should be taken care of..
I don't see what owasp has to do with this question though. Clearly, he is asking about removing the field after it has been validated, which means it is no longer going to be used for the rest of the request lifecycle. This also implies he understands its purpose. I do agree, however, that removing it does not gain any benefit whatsoever.