@csrf-armor/core

Framework-agnostic CSRF protection core functionality
171,217 7
Install
npm install @csrf-armor/core
Latest Version:1.3.1
License:MIT
Last Updated:Oct 19, 2026
Links: GitHub  ·  npm
Maintainer: muneeb_samuels

@csrf-armor/core

CSRF Armor

CodeQL CI npm version License: MIT

The framework-agnostic engine behind CSRF Armor. It has no dependencies and uses only Web APIs, so it runs on Node.js and edge runtimes.

Using Next.js, Express or Nuxt? Install the adapter instead; it includes this package: @csrf-armor/nextjs · @csrf-armor/express · @csrf-armor/nuxt

Use the core directly to support another framework, or for the low-level token helpers.

Install

npm install @csrf-armor/core

Usage

Implement CsrfAdapter for your framework, then create a protector:

import { createCsrfProtection } from '@csrf-armor/core';

const csrf = createCsrfProtection(new MyFrameworkAdapter(), {
  secret: process.env.CSRF_SECRET,
});

const result = await csrf.protect(request, response);

if (!result.success) {
  // Respond with 403. result.reason says why.
}
// Otherwise continue with result.response, which carries the token cookie and header.

The adapter guide covers the interface and includes a complete Fastify adapter.

Token helpers

import { generateNonce, generateSignedToken, parseSignedToken } from '@csrf-armor/core';

const token = await generateSignedToken(secret, 3600);   // "{expiry}.{nonce}.{signature}"
const { exp } = await parseSignedToken(token, secret);   // throws TokenExpiredError / TokenInvalidError
const nonce = generateNonce(32);                         // 64 hex characters

These only handle cryptography. They don't bind tokens to cookies or sessions; use createCsrfProtection for request protection.

Documentation

License

MIT © Muneeb Samuels

Related Packages

@csrf-armor/nuxt

Nuxt module for CSRF protection powered by csrf-armor

1,651 7
@xarenas107/nuxt-uncsrf

Nuxt module for csrf protection

855 0
vue-laravel-csrf

This Package will allow you to include the Laravel's csrf token to the forms ins...

1,336 1
nuxt-csurf

Nuxt Cross-Site Request Forgery (CSRF) Prevention

6,263,746 91
vue-dog-form

The simplest vue 3 form validation plugin.

65,599 8

Version History

Version Released License
1.3.1 MIT
1.3.0 MIT
1.2.4 MIT
1.2.3 MIT
1.2.2 MIT