Back to Blog
high SEVERITY7 min read

How Middleware/Proxy Bypass Happens in Next.js App Router with Turbopack and Single Locale and How to Fix It

A critical middleware and proxy bypass vulnerability (CVE-2026-64642) was discovered in Next.js 16.0.7 when using the App Router with Turbopack and single locale configurations. This vulnerability could allow attackers to circumvent security middleware and access protected routes. The fix requires upgrading Next.js from version 16.0.7 to 16.2.11, which patches the routing logic that handles locale-based request interception.

O
By Orbis AppSec
Published July 23, 2026Reviewed July 23, 2026

Answer Summary

CVE-2026-64642 is a middleware/proxy bypass vulnerability in Next.js App Router applications using Turbopack with single locale configurations. The vulnerability exists in Next.js versions prior to 16.2.11, where the routing engine fails to properly enforce middleware guards and proxy rules when processing internationalized requests. The fix is to upgrade Next.js to version 16.2.11 or later, which corrects the request interception logic in Turbopack's route matching engine and ensures middleware is properly invoked for all request paths.

Vulnerability at a Glance

cweCWE-863 (Incorrect Authorization), CWE-941 (Incorrectly Specified Initialization with Hard-Coded Network Resource Configuration Data)
fixUpgrade Next.js from 16.0.7 to 16.2.11 to apply patches to the request interception and middleware routing logic
riskAttackers could bypass authentication middleware and access protected routes or sensitive data
languageJavaScript/TypeScript (Next.js framework)
root causeTurbopack's route matching engine incorrectly handles middleware enforcement for single-locale App Router configurations
vulnerabilityMiddleware/Proxy Bypass in Next.js App Router (Turbopack + Single Locale)

How Middleware/Proxy Bypass Happens in Next.js App Router with Turbopack and Single Locale and How to Fix It

Understanding the Vulnerability

In Next.js applications using the App Router with Turbopack bundler and single locale configurations, a critical security flaw existed in versions 16.0.7 and earlier. This vulnerability (CVE-2026-64642) allowed attackers to bypass middleware guards and proxy rules, potentially gaining unauthorized access to protected routes and sensitive data.

The issue wasn't in your application code—it was in Next.js's internal request routing engine. When Turbopack processed requests in a single-locale setup, it failed to properly invoke middleware for certain request patterns, creating a window of opportunity for attackers to access resources that should have been protected.

The Root Cause: How the Vulnerability Works

Next.js middleware is designed to run before your application code executes. It's the first line of defense for authentication, authorization, rate limiting, and other security controls. In your middleware, you might have code like this:

// middleware.ts
import { NextRequest, NextResponse } from 'next/server';

export function middleware(request: NextRequest) {
  // Check if user is authenticated
  const token = request.cookies.get('auth-token');

  if (!token) {
    return NextResponse.redirect(new URL('/login', request.url));
  }

  return NextResponse.next();
}

export const config = {
  matcher: ['/((?!_next/static|_next/image|favicon.ico).*)'],
};

This middleware should protect all routes. However, in Next.js 16.0.7 with Turbopack and single locale configuration, the request routing engine had a flaw in how it matched routes before invoking middleware. Specifically:

  1. Request interception logic: Turbopack's route matching engine would process locale-prefixed requests
  2. Middleware enforcement gap: For certain request patterns in single-locale setups, the engine would skip middleware invocation
  3. Direct route access: Attackers could craft requests that bypassed the matcher entirely, accessing protected routes without authentication

The vulnerability existed in the pnpm-lock.yaml dependency tree because Next.js 16.0.7 contained the buggy routing logic. The Vercel Analytics integration and next-intl internationalization library both depend on Next.js's core routing, making them affected by this flaw.

Attack Scenario

Consider a typical e-commerce application:

GET /api/admin/users → Protected by middleware (requires admin token)
GET /admin/dashboard → Protected by middleware (requires admin token)

With the CVE-2026-64642 vulnerability, an attacker could potentially craft a request that bypassed middleware:

GET /api/admin/users?locale=en  
// Middleware might not invoke due to locale parameter handling in Turbopack
// Application receives request without authentication check
// Attacker gains access to sensitive user data

In a single-locale configuration (where your app only serves one language), Turbopack's optimization logic incorrectly assumed certain request patterns didn't need middleware re-evaluation, creating the bypass.

The Fix: Upgrading Next.js

The security patch was released in Next.js 16.2.11. The fix involved correcting the request interception logic in Turbopack's route matching engine to ensure middleware is always invoked before application code executes, regardless of locale configuration or request parameters.

Here's what changed in your project:

Before (Vulnerable):

{
  "dependencies": {
    "next": "16.0.7",
    "next-intl": "^4.5.0",
    "@vercel/analytics": "^1.5.0"
  }
}

After (Patched):

{
  "dependencies": {
    "next": "16.2.11",
    "next-intl": "^4.5.0",
    "@vercel/analytics": "^1.5.0"
  }
}

The lock file updates reflect that Next.js 16.2.11 is now installed:

# Before
next:
  specifier: 16.0.7
  version: 16.0.7(@babel/core@7.28.5)(react-dom@19.2.0(react@19.2.0))(react@19.2.0)

# After
next:
  specifier: 16.2.11
  version: 16.2.11(@babel/core@7.28.5)(react-dom@19.2.0(react@19.2.0))(react@19.2.0)

All dependent packages (next-intl, @vercel/analytics) are automatically updated to use the patched Next.js version.

What Changed in Next.js 16.2.11

While the exact internal changes aren't detailed in this PR, the fix addresses:

  1. Middleware invocation guarantee: The routing engine now ensures middleware runs for all requests, including those with locale parameters
  2. Turbopack route matching: Corrected the optimization logic that was incorrectly skipping middleware for single-locale configurations
  3. Request interception: Fixed the layer between the HTTP handler and application code to never bypass middleware guards

Why This Matters for Your App

If your Next.js application uses:
- App Router (not Pages Router)
- Turbopack bundler (for faster local development)
- Single locale configuration (or even multi-locale with certain setups)
- Middleware for authentication or authorization

...then you were vulnerable to this bypass. Any attacker could potentially:
- Access protected admin panels without authentication
- Retrieve sensitive API data
- Modify resources they shouldn't have permission to touch
- Bypass rate limiting or other security controls

How to Verify the Fix

After upgrading to Next.js 16.2.11, verify the fix:

# Update dependencies
pnpm install

# Check the installed version
pnpm list next
# Should show: next@16.2.11

# Test your middleware
npm run dev

# In another terminal, test a protected route
curl -i http://localhost:3000/api/admin/users
# Should be redirected to /login or return 401 Unauthorized
# NOT return 200 with data

Prevention & Best Practices

1. Keep Next.js Updated
- Subscribe to Next.js security advisories: https://github.com/vercel/next.js/security/advisories
- Update to patch versions promptly (16.0.7 → 16.2.11)
- Use tools like Dependabot to automate dependency updates

2. Test Middleware Thoroughly

// middleware.test.ts
import { middleware } from './middleware';
import { NextRequest } from 'next/server';

describe('Middleware Security', () => {
  test('should reject unauthenticated requests', () => {
    const request = new NextRequest(new URL('http://localhost:3000/api/admin'));
    const response = middleware(request);
    expect(response.status).toBe(307); // Redirect to login
  });

  test('should reject requests with missing auth token', () => {
    const request = new NextRequest(new URL('http://localhost:3000/api/admin?locale=en'));
    const response = middleware(request);
    expect(response.status).toBe(307);
  });
});

3. Use Comprehensive Matcher Patterns

export const config = {
  matcher: [
    // Protect all API routes
    '/api/:path*',
    // Protect admin routes
    '/admin/:path*',
    // Explicitly include locale variants
    '/(en|es|fr)/api/:path*',
  ],
};

4. Implement Defense in Depth
Don't rely solely on middleware. Add authentication checks at the API route level too:

// app/api/admin/users/route.ts
import { verifyAuth } from '@/lib/auth';

export async function GET(request: Request) {
  // Middleware should have already checked, but verify again
  const user = await verifyAuth(request);
  if (!user?.isAdmin) {
    return Response.json({ error: 'Unauthorized' }, { status: 401 });
  }

  return Response.json({ users: [] });
}

5. Use Dependency Scanning Tools
- Trivy: Scans for known vulnerabilities in dependencies (detected this CVE)
- npm audit: Built-in vulnerability scanner
- Snyk: Comprehensive dependency scanning
- OWASP Dependency-Check: Open-source tool

Key Takeaways

  • Turbopack's single-locale optimization had a bug: The route matching engine incorrectly skipped middleware invocation for certain request patterns, creating a bypass vector
  • Upgrade immediately: CVE-2026-64642 is HIGH severity and affects all Next.js 16.0.x users with App Router + Turbopack + single locale
  • Dependency scanning caught this: Trivy's CVE-2026-64642 rule detected the vulnerable Next.js version in your lock file
  • Always verify middleware executes: Test that authentication checks run for all request paths, including those with query parameters or locale prefixes
  • Defense in depth is essential: Don't trust middleware alone—add authorization checks at the route handler level too

How Orbis AppSec Detected This

Source: The vulnerable Next.js version (16.0.7) in package.json and pnpm-lock.yaml dependency tree

Sink: Next.js's internal request routing engine in Turbopack's route matching logic, which handles middleware invocation for App Router applications

Missing control: The routing engine lacked proper validation to ensure middleware always executes before route handlers, particularly for single-locale configurations with Turbopack

CWE: CWE-863 (Incorrect Authorization) and CWE-941 (Incorrectly Specified Initialization with Hard-Coded Network Resource Configuration Data)

Fix: Upgrade Next.js from 16.0.7 to 16.2.11, which patches the request interception and middleware enforcement logic in Turbopack's routing engine

Orbis AppSec automatically detected this vulnerability and opened a pull request with the fix. Try Orbis AppSec on your repositories to find and fix issues like this automatically.

Conclusion

CVE-2026-64642 demonstrates a critical principle in web security: framework bugs can bypass application-level security controls. Even if your middleware code is perfect, a flaw in the framework's request routing can render it ineffective.

The good news is that Vercel released a patch quickly, and upgrading is straightforward. By updating to Next.js 16.2.11, you ensure that:

  1. Middleware always runs before application code
  2. Attackers cannot bypass authentication or authorization checks through request manipulation
  3. Your application's security posture is restored

Make this upgrade a priority in your Next.js projects, especially if you're using App Router with Turbopack. And remember: keep your dependencies updated. Security patches like this are released for a reason.


References

Frequently Asked Questions

What is a middleware bypass vulnerability?

A middleware bypass occurs when an attacker can circumvent security checks (authentication, authorization, rate limiting) by exploiting flaws in how the framework processes requests. In Next.js, this means middleware guards fail to execute for certain request patterns.

How do you prevent middleware bypass in Next.js?

Keep Next.js updated to the latest stable version, test middleware with various locale configurations, use comprehensive route patterns in middleware matchers, and avoid relying solely on URL patterns for security decisions.

What CWE is this middleware bypass?

This vulnerability maps to CWE-863 (Incorrect Authorization) and CWE-941 (Incorrectly Specified Initialization), as the middleware authorization logic fails to execute properly due to misconfigured request routing.

Is using middleware matchers enough to prevent this bypass?

Middleware matchers alone are not sufficient if the underlying routing engine has bugs. This CVE demonstrates that even properly configured matchers can be bypassed if the framework's request interception logic is flawed—framework updates are essential.

Can static analysis detect this middleware bypass?

Static analysis can flag outdated Next.js versions using dependency scanning (as Trivy did here), but detecting the actual bypass logic requires runtime testing or dynamic analysis of request routing under specific locale configurations.

View the Security Fix

Check out the pull request that fixed this vulnerability

View PR #8

Related Articles

high

How Sensitive Data Exposure happens in Zotero plugins and how to fix it

A high-severity data exposure vulnerability in `Zotero.ts` automatically transmitted complete document metadata—including private notes, attachment paths, and tags—to external LLM services without user consent. The fix replaces broad `item.toJSON()` serialization with explicit field selection, sending only essential bibliographic data.

high

How SQL-injection-style template literal injection happens in JavaScript DOM rendering and how to fix it

A Semgrep rule (`utils.custom.sql-injection-template-literal`) flagged `src/export/SheetMusicView.js` for building a query/markup string out of a JavaScript template literal with untrusted values interpolated directly into it. In this case the sink was an `<option value="${s.id}">${s.name}</option>` string used to build the snippet picker, meaning any snippet name containing `"` or `<` could break out of the attribute and inject arbitrary HTML. The fix introduces an `_escapeHtml()` helper and ro

high

How missing dependency update cooldowns happen in GitHub Dependabot configurations and how to fix it

A semgrep scan flagged `.github/dependabot.yml` for lacking a cooldown period, meaning Dependabot would immediately propose updates to brand-new package versions across npm, Bundler, and Docker ecosystems. The fix adds a `cooldown: default-days: 7` block to every `package-ecosystem` entry, forcing a one-week waiting period before newly published releases are considered — reducing exposure to malicious or unstable package drops.

high

How Command Injection Happens in Node.js child_process and How to Fix It

A high-severity command injection vulnerability was discovered in `server.js` where user-controlled file paths were passed directly to shell commands via `exec()`. By migrating from `exec()` to `execFile()` and using argument arrays instead of string concatenation, the fix eliminates the attack surface while preserving the intended trash/delete functionality across macOS, Windows, and Linux.

high

How dependabot-missing-cooldown happens in GitHub Actions/Node.js and how to fix it

The repository's `.github/dependabot.yml` had no cooldown period configured, meaning Dependabot could immediately propose updates to newly published package versions with zero time for the community to flag malware or instability. The fix adds a `cooldown` block with `default-days: 7` to both the `npm` and `github-actions` ecosystems, forcing a 7-day waiting period before new releases are surfaced as update PRs.

high

How JavaScript Injection via String Interpolation Happens in Go Wails Applications and How to Fix It

A high-severity JavaScript injection vulnerability in `internal/clusterconfigs/input.go` allowed arbitrary code execution through malicious kubeconfig filenames. The `saveClusterConfigFile` function at line 20 constructed JavaScript code by directly interpolating unsanitized filenames into `window.ExecJS()` calls, enabling attackers to break out of string literals and execute arbitrary JavaScript in the Webview context.