@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
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
vue-laravel-csrf
This Package will allow you to include the Laravel's csrf token to the forms ins...
1,336
1
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 | |
| 1.2.1 | MIT | |
| 1.2.0 | MIT | |
| 1.1.0 | MIT | |
| 1.0.3 | MIT | |
| 1.0.2 | MIT | |
| 1.0.1 | MIT | |
| 1.0.0 | MIT | |
| 0.0.1 |