Search code examples
laravelamazon-web-servicesamazon-elastic-beanstalkamazon-cloudfrontamazon-elb

AWS Cloudfront causing CSRF Token Mismatch Exception


Alright hello, I have deployed my Laravel app on AWS ELB and I set up Cloudfront distribution for my app. Now I am facing CSRF Token mismatch. I know that this error can be caused by multiple config values that may be wrong. Now I have managed to fix this issue by myself in the past, but it was a long time ago and I don't know what I did and where. So if you have some tips on what could be wrong and where, then definitely send them my way. Thanks

EDIT: The exception happens after switching to Cloudfront. My problem is to get it working with Cloudfront.


Solution

  • So the problem was with forwarding of cookies, especially the XSRF_TOKEN cookie. Cookies aren't forwarded by default through the cloudfront, you have to set up a whitelist to do that. Just edit the cloudfront distribution it's in Behaviours section. Another cookies to consider forwarding are laravel_session if you use cookie sessions and remember_* if you use remember login feature.