Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

felipe-dsdev's avatar

CSRF token mismatch in Lambda Function

I'm using Laravel Nova and on login I have the following error: CSRF token mismatch.

On the server side I use the Serverless Framework to deploy on the AWS Lambda Function with provided.al2 runtime, with the bref layer php-8.1-fpm.

For CloudFront I use the serverless-lift library to configure it.

Laravel info:

  • Laravel version: 9.21.3
  • Cache Driver: DynamoDB
  • Session Driver: DynamoDB
  • Session lifetime: 120

I've tried everything, I was using cookie as a session driver and I switched to DynamoDB, set the SESSION_DOMAIN variable and nothing seems to work.

Has anyone gone through something similar and can help me?

0 likes
2 replies
Nihir's avatar
Nihir
Best Answer
Level 50

Hi @felipe-dsdev , please check the reference.

data: {

        "_token": "{{ csrf_token() }}",
        "id": id

}
https://stackoverflow.com/questions/32738763/laravel-csrf-token-mismatch-for-ajax-post-request
felipe-dsdev's avatar

Hi @nihir I solved the problem.

I'm using CloudFront and it wasn't passing the header with the token, so I configured it correctly, it worked.

Thanks for the help.

1 like

Please or to participate in this conversation.