TokenMismatch ONLY Some browsers - Laravel 5 Fresh / Production

One browser example: IE 11: Mozilla / 5.0 (Windows NT 6.1, WOW64; Trident / 7.0; rv: 11.0), like Gecko

The session began at 22:46:56. Fills out the form. Submits the form at 22:53:18, receives a TokenMismatchException . So, in just 6 minutes.

Session Start:

Apr 02 22:46:56 production.INFO: Session {"start":1428040016,"id":"8040cc779df0330855f8fa30483af63557aaf9c4","token":"L3nU4ehseV5w1iXy86g18FsgnVs6sAcDNjTUZ5QV","ip":"74.XX","method":"GET","url":"https://sub.domain.com/place-st","ua":"Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko"} []

The user submits the form in 6 minutes:

Apr 02 22:53:18 production.DEBUG: REQUEST SESSION token: 8L3pba9ALBVBcrvIPM5wnTl7bP0slSIrjCAkfWzh [] [] Apr 02 22:53:18 production.DEBUG: REQUEST INPUT _token: L3nU4ehseV5w1iXy86g18FsgnVs6sAcDNjTUZ5QV [] [] Apr 02 22:53:18 production.DEBUG: REQUEST HEADER X-CSRF-TOKEN: [] [] Apr 02 22:53:18 production.DEBUG: REQUEST HEADER X-XSRF-TOKEN: [] [] Apr 02 22:53:18 production.DEBUG: REQUEST URL: https://sub.domain.com/requests/post [] []

Server Vars:

Apr 02 22:53:18 production.DEBUG: array ( 'USER' => 'forge', 'HOME' => '/home/forge', 'FCGI_ROLE' => 'RESPONDER', 'APP_ENV' => 'production', 'QUERY_STRING' => '', 'REQUEST_METHOD' => 'POST', 'CONTENT_TYPE' => 'application/x-www-form-urlencoded', 'CONTENT_LENGTH' => '867', 'SCRIPT_FILENAME' => '/home/forge/doamin.com/public/index.php', 'SCRIPT_NAME' => '/index.php', 'REQUEST_URI' => '/requests/post', 'DOCUMENT_URI' => '/index.php', 'DOCUMENT_ROOT' => '/home/forge/doamin.com/public', 'SERVER_PROTOCOL' => 'HTTP/1.1', 'GATEWAY_INTERFACE' => 'CGI/1.1', 'SERVER_SOFTWARE' => 'nginx/1.6.2', 'REMOTE_ADDR' => '74.XX', 'REMOTE_PORT' => '56563', 'SERVER_ADDR' => '104.XX', 'SERVER_PORT' => '443', 'SERVER_NAME' => 'doamin.com', 'HTTPS' => 'on', 'REDIRECT_STATUS' => '200', 'HTTP_ACCEPT' => 'text/html, application/xhtml+xml, */*', 'HTTP_REFERER' => 'https://sub.domain.com/place-st', 'HTTP_ACCEPT_LANGUAGE' => 'en-US', 'HTTP_USER_AGENT' => 'Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko', 'HTTP_CONTENT_TYPE' => 'application/x-www-form-urlencoded', 'HTTP_ACCEPT_ENCODING' => 'gzip, deflate', 'HTTP_HOST' => 'sub.domain.com', 'HTTP_CONTENT_LENGTH' => '867', 'HTTP_CONNECTION' => 'Keep-Alive', 'HTTP_CACHE_CONTROL' => 'no-cache', 'PHP_SELF' => '/index.php', 'REQUEST_TIME_FLOAT' => 1428040398.7879851, 'REQUEST_TIME' => 1428040398, ) [] []

Session / Cookie

Apr 02 22:53:18 production.DEBUG: REQUEST PATH: requests/post [] [] Apr 02 22:53:18 production.DEBUG: COOKIE: array ( ) [] [] Apr 02 22:53:18 production.DEBUG: SESSION: array ( '_token' => '8L3pba9ALBVBcrvIPM5wnTl7bP0slSIrjCAkfWzh', ) [] []

HTTP request:

Apr 02 22:53:18 production.DEBUG: POST /requests/post HTTP/1.1 Accept: text/html, application/xhtml+xml, */* Accept-Encoding: gzip, deflate Accept-Language: en-US Cache-Control: no-cache Connection: Keep-Alive Content-Length: 867 Content-Type: application/x-www-form-urlencoded Host: sub.domain.com Referer: https://sub.domain.com/place-st User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko _token=L3nU4ehseV5w1iXy86g18FsgnVs6sAcDNjTUZ5QV&var=value&var2=value2&etc... [] []

+6
source share
3 answers

This sounds just like this famous issue with Laravel: https://github.com/laravel/framework/issues/8172

The reason is not yet known, and it continues for some time. It has a lot of smart people, but the seemingly randomness of the problem makes debugging difficult.

I suggest you enter your information on this ticket and look there for more information. In particular, we need as much information as possible about the server configuration and application configuration, so we can try to reproduce the problem. So far, the exact method of replication is unknown, which complicates the task.

+1
source

Most likely, the problem is not related to browsers. I believe that there are people who wait too long and the session ends. After submitting a form with an expired session, a TokenMismatchException occurs.

For debugging, you can save a log when each of the sessions is created to find out if it has expired, and you can also play with the session lifetime in session.php

0
source

It may be a long shot, but the source of the problem may be IE compatibility mode and various sessions of these modes.

Can you try adding this line on top of the receive and publish pages:

 header("X-UA-Compatible: IE=Edge"); 
0
source

Source: https://habr.com/ru/post/984532/


All Articles