You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

simple-next-csrf

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple-next-csrf

This project aims to add Cross-Site Request Forgery (CSRF) protection to a Next.js application that does have server-side props support.

1.0.4
latest
Source
npmnpm
Version published
Weekly downloads
2
-71.43%
Maintainers
1
Weekly downloads
 
Created
Source

simple-next-csrf

This project aims to add Cross-Site Request Forgery (CSRF) protection to a Next.js application that does have server-side props support.

Installation

npm install simple-next-csrf

Usage

create a file named csrf.js

import { simpleNextCSRF } from "simple-next-csrf";

const { csrfEnjector, csrfValidator } = simpleNextCSRF({
  secret: "hello-world",
  // your secret from environment variable
});

export { csrfEnjector, csrfValidator };

in page to enject CSRF token wrap getServerSideProps in csrfEnjector


import { csrfEnjector } from "../csrf";

export default function Home() {

  return (
    <main>
      ....
    </main>
  );
}

export const getServerSideProps = csrfEnjector((context) => {
  return {
    props: {},
  };
});

Wrap api handler in csrfValidator

import { csrfValidator } from "../../csrf";

function handler(req, res) {
  res.status(200).json({ name: "John Doe" });
}

export default csrfValidator(handler);

Keywords

next

FAQs

Package last updated on 14 May 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts