mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[PR #203] [MERGED] fix: throw on missing middleware/proxy exports instead of failing open #384
Labels
No labels
enhancement
enhancement
good first issue
help wanted
nextjs-tracking
nextjs-tracking
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/vinext#384
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/cloudflare/vinext/pull/203
Author: @southpolesteve
Created: 2/28/2026
Status: ✅ Merged
Merged: 2/28/2026
Merged by: @southpolesteve
Base:
main← Head:fix/middleware-export-validation📝 Commits (4)
50e54ebfix: throw on missing middleware/proxy exports instead of failing openbb62ff5fix: update export precedence test to match Next.js behavior (named > default)df1c06bfix: use ?? instead of || in generated middleware export resolution for consistencyc0b47fdfix: update app-router test to match new export validation behavior📊 Changes
7 files changed (+247 additions, -22 deletions)
View changed files
📝
AGENTS.md(+28 -4)📝
packages/vinext/src/index.ts(+10 -3)📝
packages/vinext/src/server/app-dev-server.ts(+14 -3)📝
packages/vinext/src/server/middleware.ts(+49 -6)📝
tests/app-router.test.ts(+5 -4)📝
tests/pages-router.test.ts(+2 -2)📝
tests/shims.test.ts(+139 -0)📄 Description
Summary
Middleware and proxy files that don't export the expected function (e.g. misspelled export, wrong named export, no exports at all) were silently skipped, letting requests through unprotected. This is a security-relevant bug: if someone typos
export function prooxy()in their auth middleware, requests bypass it entirely with no warning.Next.js throws a
ProxyMissingExportErrorin this scenario. This PR matches that behavior.Changes
server/middleware.ts: AddedisProxyFile()andresolveMiddlewareHandler()that validates exports based on file type, then throws if no valid export is foundindex.ts(Pages Router prod): Updated generated code to check correct exports per file type and throw on mismatch (also fixes the missingproxyexport check from #188)server/app-dev-server.ts(App Router): Same validation in the generated RSC entrytests/shims.test.ts: 14 new tests covering all valid/invalid export combinations for both proxy.ts and middleware.ts filesAGENTS.md: Added "Searching the Next.js Test Suite" as a required workflow step to prevent this class of bug in the futureValidation rules (matching Next.js)
proxy.tsproxy,defaultmiddleware, any other name, no exportmiddleware.tsmiddleware,defaultproxy, any other name, no exportPorted from Next.js
Tests ported from
test/e2e/app-dir/proxy-missing-export/proxy-missing-export.test.ts.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.