Passer au contenu

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?

demandé il y a 2 ans610 vues

1 réponse
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

répondu il y a 2 ans

Vous n'êtes pas connecté. Se connecter pour publier une réponse.

Une bonne réponse répond clairement à la question, contient des commentaires constructifs et encourage le développement professionnel de la personne qui pose la question.