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?

ACaucci
asked 23 days ago105 views
1 Answer
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
EXPERT
Mike_L
answered 22 days ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions