RepositoryJavaScript
electrode-io

electrode-io/electrode-csrf-jwt

Stateless Cross-Site Request Forgery (CSRF) protection with JWT

125sao
21fork
1issue
3lượt xem

🔐 Bảo vệ CSRF không trạng thái bằng JWT

Giải pháp stateless CSRF an toàn cho ứng dụng Electrode, Express, Hapi, Koa 2.

electrode-csrf-jwt là một plugin cung cấp bảo vệ CSRF không trạng thái bằng cách sử dụng JWT. Thích hợp cho các hệ thống không lưu trữ session phía server, nơi việc xác thực truyền thống trở nên phức tạp.

✨ Điểm nổi bật

  • Hai token JWT ghép UUID: Một token trong cookie, một trong header HTTP, cùng payload nhưng khác type và UUID giống nhau để ghép cặp.
  • Kỹ thuật double submit mở rộng: Dựa trên nguyên tắc hai kênh cookie và header mà script không thể đọc/ghi để xác thực.
  • Hỗ trợ HTTP Only cookie: Cookie được đặt thành HTTP Only để chặn truy cập bởi bất kỳ script nào.
  • Tích hợp đa nền tảng: Hỗ trợ plugin cho Hapi, middleware cho Express, Koa 2 và Fastify.
  • Token engine thay đổi được: Hỗ trợ cấu hình engine token JWT hoặc hash (thử nghiệm).
  • Cấu hình linh hoạt: Tùy chỉnh tên cookie/header, secret, UUID generator và cấu hình cookie chi tiết.
  • Tài liệu demo đầy đủ: Cung cấp ví dụ sử dụng với Hapi Node.js server.

💡 Vì sao đáng chú ý

Khác với các giải pháp CSRF truyền thống cần session lưu trữ server, electrode-csrf-jwt hoạt động hoàn toàn stateless — chỉ cần hai token JWT được ghép bởi UUID. Điều này giúp triển khai dễ dàng trong kiến trúc microservices hoặc serverless mà không cần quản lý trạng thái.

Tuy nhiên, do phụ thuộc vào header HTTP, mọi request phải thực hiện qua AJAX. Ngoài ra, tab trình duyệt độc lập có thể gây xung đột token — nhưng các giải pháp tham khảo có sẵn trong demo.


#CSRF #JWT #Security #Stateless #TiniX

Dự án tương tự

Khám phá các dự án và mô hình AI khác có sự tương đồng.

RepositoryJavaScript
simov/grant

OAuth Proxy

4.2k
Feb 4, 2025
RepositoryJavaScript
animir/node-rate-limiter-flexible

Atomic and non-atomic counters and rate limiting tools. Limit resource access at any scale.

3.6k
Nov 25, 2026
RepositoryJavaScript
ButterCMS/buttercms-js

Node/JS API client for ButterCMS (https://buttercms.com)

164
Nov 13, 2025
RepositoryTypeScript
nextauthjs/next-auth

Authentication for the Web.

28.4k
Jul 22, 2026
Repository
shieldfy/API-Security-Checklist

Checklist of the most important security countermeasures when designing, testing, and releasing your API

23.4k
Jul 21, 2026
RepositoryTypeScript
apollographql/apollo-server

🌍  Spec-compliant and production ready JavaScript GraphQL server that lets you develop in a schema-first way. Built for Express, Connect, Hapi, Koa, and more.

14.0k
Nov 22, 2026
RepositoryJava
jwtk/jjwt

Java JWT: JSON Web Token for Java and Android

11.1k
Nov 10, 2026
RepositoryElixir
ueberauth/guardian

Elixir Authentication

3.5k
Aug 18, 2026
RepositoryC#
damienbod/bff-aspnetcore-angular

Backend for frontend security using Angular CLI and ASP.NET Core backend

148
Nov 17, 2026