Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TokenMismatchException RANDOM via ajax requests only on Chrome Windows #13949

Closed
sebastianvirlan opened this issue Jun 11, 2016 · 5 comments
Closed

Comments

@sebastianvirlan
Copy link

How this can be explained?

  1. Clean install Laravel
  2. Using redis for session and cache
  3. The problem occur only if I start the server on windows and only shows on Chrome.
  4. Using a simple js function for ajax call:

        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            },
            data: {
                _token: $('meta[name="csrf-token"]').attr('content')
            }
        });

        for(var i = 0; i < 5; i++){

            getUsers();
        }

        function getUsers() {
            $.ajax({
                url: '/users',
                type: 'POST',
                success: function(data) {
                    console.log(data);
                }
            });
        }

  1. Setting CSRF in meta <meta name="csrf-token" content="{{ csrf_token() }}" />
  2. Returning a JSON with data:
    public function users() {

        $users = User::all();

        return response()->json([
            'users' => $users,
        ]);
    }
  1. At the final of the video you can see RANDOM TokenMismatchException even the token never change but sometime error occur.

https://www.youtube.com/watch?v=QDucHoP647g

I know this problem has been discussed from years but why does not exist a solution for this?

@GrahamCampbell
Copy link
Member

Thanks. This is a known issue. Please see the existing issues. If you make sure you avoid concurrent requests that start a session, you should be fine.

@sebastianvirlan
Copy link
Author

I don't understand this part:

If you make sure you avoid concurrent requests that start a session, you should be fine.

Please give me some more details.

@GrahamCampbell
Copy link
Member

GrahamCampbell commented Jun 11, 2016

Sorry, but this is not a support forum. Feel free to read the multitude of other replies I've given to similar issues.

@sebastianvirlan
Copy link
Author

Ok, thank you.

@sebastianvirlan
Copy link
Author

If this helps you with something, the problem occur only when I login with Remember Me checked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants