daker52/nextjs-app-router-security-lab
GitHub: daker52/nextjs-app-router-security-lab
面向 Next.js App Router 的实践型安全实验室,通过漏洞与修复版本的对照帮助开发者理解并修复 Server Actions、RSC、middleware 等场景下的安全问题。
Stars: 0 | Forks: 0
# Next.js App Router 安全实验室
**针对 Next.js 16+ App Router 的实践漏洞模式与修复方案 —— 涵盖 Server Actions、RSC 边界、middleware 和 secrets。**
[](https://nextjs.org/)
[](./LICENSE)
[](./modules)
[](https://github.com/daker52/nextjs-app-router-security-lab/actions)
[快速开始](#-quick-start) ·
[模块](#-modules-mvp) ·
[方法论](./docs/METHODOLOGY.md) ·
[工具映射](./docs/TOOL-MAPPING.md) ·
[路线图](./ROADMAP.md) ·
[法律声明](./docs/LEGAL-AND-ETHICS.md)
**相关仓库:** [Security Shield(安全基线)](https://github.com/daker52/Next.js---Security-shield-list-help) · [Pentest Toolkit(OSS 工具)](https://github.com/daker52/opensource-pentest-toolkit)
## 为什么会有这个实验室
大多数安全实验室(如 DVWA、WebGoat、Juice Shop)针对的是 PHP 或传统技术栈。**Next.js App Router** 引入了新的攻击面:
- **Server Actions** 的行为类似于公开的 HTTP API
- **React Server Components** 模糊了服务器端/客户端的数据边界
- **Middleware 匹配器** 极易配置错误
本仓库将每个缺陷与其**安全对应的实现**相匹配,并链接到检测工具和生产级模式。
```
flowchart LR
subgraph lab [This repo]
V[vulnerable variant]
S[secure variant]
end
subgraph ecosystem [Ecosystem]
PT[Pentest Toolkit]
SH[Security Shield]
end
V -->|exploit in lab| S
S -->|implement in prod| SH
PT -->|scanning tools| V
```
## 快速开始
### 前置条件
- Node.js 20+
- npm 10+
### 安装
```
git clone https://github.com/daker52/nextjs-app-router-security-lab.git
cd nextjs-app-router-security-lab
npm install
```
### 运行模块
```
# 易受攻击的 variant(了解 bug)
npm run dev:module -- 01-server-action-no-auth vulnerable
# http://localhost:3001
# 安全的 variant(查看修复)
npm run dev:module -- 01-server-action-no-auth secure
# http://localhost:3011
```
### Docker(可选)
```
docker compose up module01-vulnerable
# http://localhost:3001
```
### 构建所有应用(CI 执行此操作)
```
npm run build:modules
```
## 模块(MVP)
| # | 模块 | CWE 重点 | 漏洞端口 | 安全端口 |
|---|--------|-----------|-----------|-------------|
| 01 | [server-action-no-auth](./modules/01-server-action-no-auth/) | 缺少授权 | 3001 | 3011 |
| 02 | [server-action-no-zod](./modules/02-server-action-no-zod/) | 输入验证不当 | 3002 | 3012 |
| 03 | [idor-server-action](./modules/03-idor-server-action/) | IDOR | 3003 | 3013 |
| 05 | [secret-in-client-bundle](./modules/05-secret-in-client-bundle/) | 敏感数据暴露 | 3005 | 3015 |
| 06 | [weak-middleware-matcher](./modules/06-weak-middleware-matcher/) | 缺少身份验证 | 3006 | 3016 |
每个模块目录包含:
```
modules/XX-name/
├── README.md # Threat model, exploit steps, remediation
├── vulnerable/ # Broken Next.js mini-app
└── secure/ # Patched version
```
## 学习路径
1. 阅读 [docs/METHODOLOGY.md](./docs/METHODOLOGY.md)
2. 按顺序完成模块 **01 → 02 → 03 → 05 → 06**
3. 将发现结果映射到 [docs/TOOL-MAPPING.md](./docs/TOOL-MAPPING.md)
4. 使用 [Next.js Security Shield](https://github.com/daker52/Next.js---Security-shield-list-help) 应用修复方案
## 敬请期待
模块 **04, 07–10**(CSRF、开放重定向、批量赋值、速率限制、Auth.js 配置错误)已在 [ROADMAP.md](./ROADMAP.md) 中追踪。想要贡献吗?请使用 [模块请求模板](./.github/ISSUE_TEMPLATE/module-request.yml)。
## 仓库结构
```
nextjs-app-router-security-lab/
├── modules/ # 5 MVP lessons (vulnerable + secure)
├── docs/ # Methodology, legal, tool mapping
├── scripts/ # dev-module, build-all
├── docker-compose.yml
└── .github/workflows/ci.yml
```
## 维护者
**OndHa** — [@daker52](https://github.com/daker52) · [wwwkkcode.cz](https://wwwkkcode.cz)
## 许可证
MIT — 详见 [LICENSE](./LICENSE)。[TOOL-MAPPING.md](./docs/TOOL-MAPPING.md) 中引用的各个工具拥有其各自的许可证。
**已在 Next.js 16.x 上测试 · 如果它帮助您了解了 App Router 的安全性,请为该仓库加星**
标签:CISA项目, MITM代理, Web安全, Web报告查看器, 前端安全, 安全实验靶场, 漏洞复现, 自动化攻击, 蓝队分析, 请求拦截