내용으로 건너뛰기

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년 전609회 조회

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년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

관련 콘텐츠