RodrigoSAlves
8 months ago
67
10
Laravel

TokenMismatch Exception - Cause: Blank Line before <?php

Posted 8 months ago by RodrigoSAlves

Good Afternoon,

I'm currently trying to deploy a Laravel 5.6 app on Hetzner Level 9 shared hosting. (unfortunately i was constrained by the client to used shared hosting).

I've already managed to upload the project with all the latest vendor dependencies installed, and the application in general seems to work fine

This is the case until I attempt to Sign In (I have the sign in right on my home page, and registration is closed for outsiders (platform administrators create the accounts as they need)).

Uppon further inspection I've spotted that the problem comes from VerifyCSRFToken when the _token received in the request is compared with the token present in the session. (function "tokensMatch").

Has anyone got any idea to why these tokens are different?

The function where it all stops:

/**
 * Determine if the session and input CSRF tokens match.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return bool
 */
protected function tokensMatch($request)
{
    
    $token = $this->getTokenFromRequest($request);
    
    return is_string($request->session()->token()) &&
           is_string($token) &&
           hash_equals($request->session()->token(), $token);

// $request->session()->token is different from $token

}

/**
 * Get the CSRF token from the request.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return string
 */
protected function getTokenFromRequest($request)
{
    $token = $request->input('_token') ?: $request->header('X-CSRF-TOKEN');

    if (! $token && $header = $request->header('X-XSRF-TOKEN')) {
        $token = $this->encrypter->decrypt($header);
    }

    return $token;
}

Please sign in or create an account to participate in this conversation.