Edge-CSRF: CSRF protection for Next.js that runs in middleware (edge runtime) #59660
Unanswered
amorey
asked this question in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi Everyone,
I just wanted to let you know about a utility I made that adds CSRF protection to Next.js apps and runs in middleware (edge runtime):
https://github.com/amorey/edge-csrf
Because it runs in middleware, CSRF checks and token generation can happen on the edge, close to your users. I've also tried to make it as easy to use as possible. Here's how you enable it in middleware:
Once it's enabled in middleware you can get the CSRF token from the HTTP headers in your components:
Try it out and let me know what you think!
Andres
Beta Was this translation helpful? Give feedback.
All reactions