跳至内容

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 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。