Skip to content

The CSRF token is invalid. Can't figure out what is wrong #11528

Closed Answered by YuriiMotov
Turum asked this question in Questions
Discussion options

You must be logged in to vote

As I see you have two csrf tokens:

  1. fastapi-csrf-token, generated by secrets.token_urlsafe(32)
  2. csrftoken, generated by csrf_protect.generate_csrf_tokens()

csrf_protect.validate_csrf(request) expects that you pass csrftoken in the x-csrf-token, but in your request you put fastapi-csrf-token into this header parameter.

So, I think you should send csrftoken instead of fastapi-csrf-token in the x-csrf-token header

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by Turum
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem
2 participants