跳至內容

Laravel csrf-token mismatch error on aws beanstalk

0

Hi, we're experiencing trouble reaching Laravel app stored in aws beanstalk envinronment with a ALB and autoscaling enabled.

Performing some actions that requiring csrf token verification we have a 419 error.

In the staging environment equal to production but with only 1 instance and autoscaling disabled this problem didn't occur.

We are pretty sure that could be related to the persistent of the session because having multiple instance serving the production beanstalk environment, probably the session initialize in one instance and continue in another one and validation of token fail, expiring the session.

How we can solve this problem?

已提問 2 年前檢視次數 608 次

1 個回答
0

As I understand, Laravel CSRF "token" is stored in user session.

Where are you storing your session data? If this is files, you will need to change it to an external shared data store. This can be database, dynamodb, redis/memcache (Elasticache). It will allow all your instances access to session data.

As a workaround, you can enable ALB sticky sessions. However, it will have some impact on scalability as web requests are not evenly distributed across all your instances.

AWS
專家

已回答 2 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。