NEXTJS CVE-2025-29927

CVE Analysis

In this blog post, we perform an analysis of a specific Next.js setup and its associated Common Vulnerabilities and Exposures (CVE) concerns. We’ll walk through the setup process, explore the project’s file structure, and dive deep into the call graph of Next.js to understand how requests are handled and how middleware plays a crucial role.


Setup

First, create a new Next.js app with the vulnerable version and prepare your debugging environment:

$ npx create-next-app@12.0.7 debug-app  
$ cd debug-app
$ rm -rf node_modules package-lock.json .git

Update package.json, to ensure you’re using the vulnerable version of Next.js (12.0.7):

{
  "name": "debug-app",
  "version": "1.0.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "next": "12.0.7", // <- vulnerable version
    "react": "17.0.2",
    "react-dom": "17.0.2"
  },
  "devDependencies": {
    "eslint": "8.4.1",
    "eslint-config-next": "12.0.7"
  }
}

After updating, install the dependencies with:

Debugging Configuration

For debugging, add the following configuration to .vscode/launch.json:

Next.js Configuration

Edit next.config.js to enable production browser source maps:

If you have a tsconfig.json, ensure you add "sourceMap": true:

Project File Structure

Here’s an overview of the current file structure (excluding node_modules):

Note:

  • Since we are using Next.js 12.0.7, the middleware file must be named middleware.js and placed in the project root. In newer versions, the middleware file is named _middleware.js and is located in the pages folder.

  • The pages folder is where the frontend source code resides (e.g., index.tsx, home.js, dashboard.tsx, etc.).

Files added:

  1. pages/dashboard/index.tsx

  2. pages/dashboard/admin/index.tsx

  3. middleware.ts

Middleware Implementation

Below is the content of middleware.ts which demonstrates how to redirect requests from /dashboard/admin to /:


Next.js Call Graph Analysis

Understanding the Next.js call graph is essential for debugging and vulnerability analysis. Here’s a high-level overview of the process:

sandbox.js:

simply said, sending

HEADER : x-middleware-subrequest: params.name:params.name:params.name:params.name:params.name sending same value in this header more than 5 time will stop this middleware from running thus bypassing the middleware to run.

Key Parameter : params.name The value of params.name represents the middleware path. In Next.js versions prior to 13, it can only be either middleware or src/middleware.

In newer versions, the naming convention changes slightly, but the analysis here is based on version 12.0.7.

Conclusion This blog post has walked through the setup and configuration of a Next.js project vulnerable to a specific CVE, explained the directory structure, detailed the middleware implementation, and analyzed the call graph for request handling. Understanding this flow is crucial not only for debugging but also for performing a thorough vulnerability analysis. By recognizing how middleware intercepts and processes requests, developers can better secure their applications and address potential weaknesses.

Feel free to experiment with the setup, review the call graph, and dive deeper into the middleware sandbox implementation to further enhance your security analysis.

Happy coding!

Last updated