Next Csrf screenshot

Next Csrf

Author Avatar Theme by J0lvera
Updated: 29 Mar 2023
141 Stars

CSRF mitigation for Next.js

Overview

next-csrf is a package designed to provide Cross-Site Request Forgery (CSRF) mitigation for websites built using Next.js. It implements the Synchronizer Token Pattern to protect API endpoints from unauthorized requests. By setting up tokens and verifying signatures on cookies, next-csrf enhances the security of Next.js applications.

Features

  • Mitigation Patterns: Implements Synchronizer Token Pattern using CSRF for enhanced security.
  • Setup Functions: Provides setup function to create necessary cookies for secret and token on SSG pages.
  • API Protection: With csrf function, protects API routes by validating and verifying token signatures.
  • Customization Options: Allows customization of token key name, error messages, ignored methods, and cookie options.

Installation

To install next-csrf, you can use yarn or npm:

Using yarn:

yarn add next-csrf

Using npm:

npm install next-csrf

Summary

next-csrf is a valuable security package for Next.js applications, offering CSRF mitigation through the implementation of the Synchronizer Token Pattern. By setting up tokens and protecting API endpoints, next-csrf helps enhance the security of Next.js websites, especially in scenarios involving authenticated users and sensitive data. With customization options available, developers have the flexibility to tailor the CSRF protection according to their specific requirements, making next-csrf a useful tool for securing Next.js applications against CSRF attacks.