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

Token mismatch #70

Open
farukaziz opened this issue Dec 20, 2020 · 4 comments
Open

Token mismatch #70

farukaziz opened this issue Dec 20, 2020 · 4 comments

Comments

@farukaziz
Copy link

Definitely it's great work.
I have a problem with token mismatch. It caches my view for GET request with html form but when submit the form it's fail because the package not updating the CSRF token in form which loaded with GET request and cached.

Getting CSRF token by ajax in html cache file might be security risk. What is the solution?

@JosephSilber
Copy link
Owner

JosephSilber commented Dec 20, 2020 via email

@farukaziz
Copy link
Author

Why do you think getting via AJAX would be a security risk?

Suppose I am getting CSRF by endpoint example.com/csrf-token

public function serveCsrf(){
  return csrf_token();
}

Now anyone can get the CSRF token by endpoint example.com/csrf-token from cross site and can make POST request easily to any POST request endpoint.

@JosephSilber
Copy link
Owner

JosephSilber commented Dec 20, 2020 via email

@jonathonbyrdziak
Copy link

Parsing content from an html page is easy, if CORS was all we needed then LinkedIn wouldn't have a problem blocking all the web scrappers. Using a headless browser is easy to capture a page and parse out the CSRF token. leaving your crsf on an endpoint is a security whole, the OP is correct.

The solution is actually already available to you, thanks to Laravel storing the CSRF in the cookie on every page visit. Check your developer toolbar for cookies and find XSRF-TOKEN storing the correct csrf token.

Just rewrite your application to pull this cookie and update it onReady.

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

3 participants