简体   繁体   中英

#laravel 419 error appear submission of any form this problem only on GoDaddy hosting on other hosting app works fine

here is the pattern of 419 error that I faced

  • login in application
  • logout
  • again login
  • on again logout 419 error appears

after login when I click on any link(that call route) 419 occur, especially when I try to delete any record this error comes out, according to my finding during this error I realize that on each form submission token store in session updated but token that passes as hidden field in form submission request is not update that is the cause of token mismatch

what did I do to figure out this problem?

current I'm using laravel 5.7.28 version , I tried with same application on other shared hosting application work fine.
I faced 419 only on the GoDaddy hosting following are the step that I follow to figure out the problem but does not get a fruitful result

1.

I comment out

    //      \App\Http\Middleware\VerifyCsrfToken::class,

from kernel.php 419 error disappear but by doing this after login when I click on any link I redirect on login screen means to say session destroyed

2.

I also regenerate app key

    APP_KEY=base64:8NYbcWPkEaj5oVHEGBWxCaFVHQhkgA/OOZyFPBiDMYQ=

3.

in session.php file

    'http_only' => false,

4.

the session is properly storying in storage/framework/session.php and I assign permissions 777

5.

enter code here

then I try to debug session manually

    vendor/laravel/framework/src/Illuminate\Foundation\Http\Middleware


    public function handle($request, Closure $next)
        {
    
     echo "<pre>";
            print_r($this->getTokenFromRequest($request));
            echo "</pre>";
    
    
            echo "<pre>";
            print_r($request->session()->token());
     echo "</pre>";
    die()
            if (
                $this->isReading($request) ||
                $this->runningUnitTests() ||
                $this->inExceptArray($request) ||
                $this->tokensMatch($request)
            ) {
                return tap($next($request), function ($response) use 
       ($request) {
                    if ($this->shouldAddXsrfTokenCookie()) {
                        $this->addCookieToResponse($request, $response);
                    }
                });
            }
    
            throw new TokenMismatchException;
        }


csrf token store in session and updated on each form submission


    $request->session()->token();

but token store in form submission $request remain same/static does not change/update


    $this->getTokenFromRequest($request);

which is actually is the cause of token mismatch that throws an exception of in the form of error 419

6.


properly use @scrf token on each form and i also replace {{csrf_filed() }}


7.

also run the composer update command

8.

run app on a different browser

9.

Comment out

    //\App\Http\Middleware\VerifyCsrfToken::class in \app\Http\Kernel.php

while I commit out above file 419 disappear but when I click on any link session destroyed, logout and I return on the login page Comment out

     //\Illuminate\Session\Middleware\AuthenticateSession::class 

in


\app\Http\Kernel.php

.env file code


    APP_NAME=Laravel
    APP_ENV=local
    APP_KEY=base64:8NYbcWPkEaj5oVHEGBWxCaFVsQhkgA/OOZyFPBiDMYQ=
    APP_DEBUG=true
    APP_URL=http://localhost
    
    LOG_CHANNEL=stack
    
    DB_CONNECTION=mysql
    DB_HOST=127.0.0.1
    DB_PORT=3306
    DB_DATABASE=ltcsar
    DB_USERNAME=root
    DB_PASSWORD=
    
    BROADCAST_DRIVER=log
    CACHE_DRIVER=file
    QUEUE_CONNECTION=sync
    SESSION_DRIVER=file
    SESSION_LIFETIME=120
    
    REDIS_HOST=127.0.0.1
    REDIS_PASSWORD=null
    REDIS_PORT=6379+
    
    MAIL_DRIVER=smtp
    MAIL_HOST=smtp.mailtrap.io
    MAIL_PORT=2525
    MAIL_USERNAME=null
    MAIL_PASSWORD=null
    MAIL_ENCRYPTION=null
    
    PUSHER_APP_ID=
    PUSHER_APP_KEY=
    PUSHER_APP_SECRET=
    PUSHER_APP_CLUSTER=mt1
    
    MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
    MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

我遇到了同样的问题,它是 laravel 5.7.2 的问题,我已经安装了 framework v 5.7.9,问题将消失。

Go to

app\\Http\\Middleware\\TrustProxies.php

update protected $proxies; --> protected $proxies = '*';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM