Skip to content

test: add test ensuring GHSA-f82v-jwr5-mffw doesn't affect Next.js on Netlify #2778

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions tests/e2e/edge-middleware.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,19 @@ test.describe('Middleware with i18n and excluded paths', () => {
})
})
})

test("requests with x-middleware-subrequest don't skip middleware (GHSA-f82v-jwr5-mffw)", async ({
middlewareSubrequestVuln,
}) => {
const response = await fetch(`${middlewareSubrequestVuln.url}`, {
headers: {
'x-middleware-subrequest': 'middleware:middleware:middleware:middleware:middleware',
},
})

// middleware was not skipped
expect(response.headers.get('x-test-used-middleware')).toBe('true')

// ensure we are testing version before the fix for self hosted
expect(response.headers.get('x-test-used-next-version')).toBe('15.2.2')
})
Comment on lines +220 to +234
Copy link
Contributor Author

@pieh pieh Mar 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is inspired by vercel/next.js@52a078d#diff-c5e08cd8ee165bce3a9fb81c8315d6e149b76f6f9b2e53f70bb2f39fb248d2aeR148-R157

Just assertions are hopefully more readable in their intention - goal is to ensure that middleware is not skipped when x-middleware-subrequest request header with 5+ hops is provided ( as then https://github.com/vercel/next.js/blob/cdb9a8c3b355593ab19ee6dec7c59e622bf59c81/packages/next/src/server/web/sandbox/sandbox.ts#L96-L114 this code path with early bail (circuit breaker to prevent infinite recursion) would be executed that would skip execution of actual middleware - at least when self hosting, but we don't even use this code path for our handling)

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function Home() {
return (
<main>
<h1>Hi</h1>
</main>
)
}
12 changes: 12 additions & 0 deletions tests/fixtures/middleware-subrequest-vuln/app/layout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const metadata = {
title: 'Simple Next App',
description: 'Description for Simple Next App',
}

export default function RootLayout({ children }) {
return (
<html lang="en">
<body>{children}</body>
</html>
)
}
13 changes: 13 additions & 0 deletions tests/fixtures/middleware-subrequest-vuln/middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { NextResponse } from 'next/server'
import { NextRequest } from 'next/server'

import packageJson from 'next/package.json'

export async function middleware(request: NextRequest) {
const response = NextResponse.next()

response.headers.set('x-test-used-middleware', 'true')
response.headers.set('x-test-used-next-version', packageJson.version)

return response
}
9 changes: 9 additions & 0 deletions tests/fixtures/middleware-subrequest-vuln/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
output: 'standalone',
eslint: {
ignoreDuringBuilds: true,
},
}

module.exports = nextConfig
20 changes: 20 additions & 0 deletions tests/fixtures/middleware-subrequest-vuln/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "middleware-subrequest-vuln",
"version": "0.1.0",
"private": true,
"scripts": {
"postinstall": "next build",
"dev": "next dev",
"build": "next build"
},
"dependencies": {
"next": "15.2.2",
"react": "18.2.0",
"react-dom": "18.2.0"
},
"test": {
"dependencies": {
"next": "15.2.2"
}
}
}
1 change: 1 addition & 0 deletions tests/utils/create-e2e-fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ export const fixtureFactories = {
pnpm: () => createE2EFixture('pnpm', { packageManger: 'pnpm' }),
bun: () => createE2EFixture('simple', { packageManger: 'bun' }),
middleware: () => createE2EFixture('middleware'),
middlewareSubrequestVuln: () => createE2EFixture('middleware-subrequest-vuln'),
middlewareI18nExcludedPaths: () => createE2EFixture('middleware-i18n-excluded-paths'),
middlewareOg: () => createE2EFixture('middleware-og'),
middlewarePages: () => createE2EFixture('middleware-pages'),
Expand Down
Loading