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 Quadratic CPU Consumption Vulnerabilities Happen in JavaScript YAML Parsers and How to Fix Them

A high-severity denial-of-service vulnerability in js-yaml versions 3.x and 4.x allowed attackers to trigger quadratic CPU consumption through specially crafted YAML documents using the !!omap tag. This fix upgrades js-yaml from 4.1.1 to 4.3.1 and from 3.14.2 to 3.15.1, eliminating the algorithmic complexity attack vector that could freeze Node.js applications processing untrusted YAML input.

high

How javascript.lang.security.detect-child-process.detect-child-process happens in Node.js and how to fix it

A high-severity command injection vulnerability was discovered in `scripts/build.js` where `execSync` was called with string-interpolated arguments (`sourceDir` and `outputPath`) inside a shell command. By replacing `execSync` with `spawnSync` using an argument array (no shell), the fix eliminates the possibility of shell metacharacter injection while preserving identical build behavior.

high

How Command Injection happens in Node.js child_process and how to fix it

A command injection vulnerability in nix.js's Release class allowed potentially malicious input through the `arch` parameter to be executed via shell commands. The fix replaced `execSync()` with `execFileSync()`, eliminating shell interpretation and preventing command injection by passing arguments as an array instead of a concatenated string.

high

How Email Exhaustion Denial of Service Happens in Node.js OTP Endpoints and How to Fix It

A Node.js authentication service exposed unauthenticated OTP endpoints without adequate rate limiting, allowing attackers to exhaust email service quotas through repeated requests. The fix implements per-session resend caps and cooldown enforcement to prevent email-based denial of service attacks while preserving legitimate user workflows.

high

How Unauthenticated Denial of Service happens in React Router and how to fix it

CVE-2026-55685 is a high-severity Denial of Service vulnerability in React Router's `@remix-run/server-runtime` that allows unauthenticated attackers to exhaust server resources by sending crafted requests to the manifest endpoint. The fix upgrades `react-router` from version 7.17.0 to 7.18.0, which tightens handling of untrusted input in route matching logic. Developers using any React Router 7.x application with server-side rendering should apply this patch immediately.

high

How package_managers.pnpm.pnpm-missing-minimum-release-age.pnpm-minimum-release-age happens in pnpm and how to fix it

A pnpm workspace configuration in `site-astro/pnpm-workspace.yaml` was missing critical supply chain security settings including `minimumReleaseAge`, `trustPolicy`, and `blockExoticSubdeps`. Without these protections, the project could install freshly published malicious packages within minutes of their release. The fix adds a 7-day quarantine period, downgrade protection, and exotic subdependency blocking.