Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 631
maranovot Avatar asked Oct 23 '25 12:10

maranovot


1 Answers

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.

like image 172
maranovot Avatar answered Oct 25 '25 07:10

maranovot



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!