Kanevry/actionguard
GitHub: Kanevry/actionguard
ActionGuard 为 Next.js Server Actions 提供一行代码集成的身份验证、速率限制、CSRF 防护和审计日志安全中间件。
Stars: 0 | Forks: 0
ActionGuard
Server Actions 的安全中间件。身份验证、速率限制、审计日志 —— 一行代码搞定。
## 为什么选择 ActionGuard Next.js Server Actions 很强大 —— 但它们只是 POST 端点背后的原始数据库调用。没有身份验证检查,没有速率限制,没有审计追踪。**少一个 `if (!user)` 检查,你的数据就会暴露。** ActionGuard 将每个 Server Action 包装在可组合的安全管道中。身份验证、速率限制、CSRF 保护和审计日志 —— 一次配置,处处生效。 ## 快速开始 ``` npm install actionguard ``` ``` // lib/action-guard.ts import { createActionGuard } from 'actionguard'; import { customAuth } from 'actionguard/auth/custom'; export const guard = createActionGuard({ auth: customAuth(async (headers) => { // Your auth logic here return getUserFromSession(headers); }), }); ``` ``` // app/actions/invoices.ts 'use server'; import { guard } from '@/lib/action-guard'; import { z } from 'zod'; const DeleteSchema = z.object({ invoiceId: z.string().uuid() }); export const deleteInvoice = guard .auth() .schema(DeleteSchema) .rateLimit({ maxRequests: 10, window: '1m' }) .audit({ action: 'DELETE', resource: 'invoices' }) .action(async ({ input, ctx }) => { await db.invoices.softDelete(input.invoiceId); return { deleted: true }; }); ``` ## 功能特性 | 功能 | 社区版 (免费) | 专业版 | |---------|-----------------|-----| | Zod Schema 验证 | ✅ | ✅ | | 身份验证 (Supabase, NextAuth, 自定义) | ✅ 3 个提供商 | ✅ 8+ 个提供商 | | 速率限制 | ✅ 内存存储 | ✅ Redis/Upstash | | CSRF 保护 | ✅ | ✅ | | 输入清洗 | ✅ | ✅ | | 审计日志 | ✅ 控制台 | ✅ 数据库适配器 | | PII 脱敏 | — | ✅ | | RBAC | ✅ 角色匹配 | ✅ 角色层级 | | GDPR/SOC2 预设 | — | ✅ | ## 身份验证提供商 ``` // Supabase import { supabaseAuth } from 'actionguard/auth/supabase'; // NextAuth / Auth.js import { nextAuth } from 'actionguard/auth/next-auth'; // Custom import { customAuth } from 'actionguard/auth/custom'; ``` ## 文档 访问 [actionguard.dev](https://actionguard.dev) 查看完整文档。 ## 贡献 请参阅 [CONTRIBUTING.md](CONTRIBUTING.md) 了解开发设置和指南。 ## 许可证 [MIT](LICENSE) —— ActionGuard 核心是免费且开源的。 [@actionguard/pro](https://actionguard.dev/pro) 需商业授权使用。标签:API 安全, API密钥检测, CISA项目, CSRF 防护, DNS解析, NPM 包, ProjectDiscovery, React, Server Actions, Streamlit, Syscalls, TypeScript, Web 安全, Zod, 中间件, 安全插件, 审计日志, 开源项目, 搜索引擎查询, 数据保护, 暗色界面, 网络安全, 自动化攻击, 访问控制, 输入验证, 配置错误, 防护管道, 隐私保护