AI summary by TwinMind
Vercel screwed up (breaking down the Next.js CVE)
Theo - t3․gg
49m 5s
Security Incident Overview
- Next.js middleware can be bypassed entirely using specific header
- CVE severity rated 9.1, affecting hundreds of thousands of Next apps
- Exploit allows skipping middleware layer with
middleware sub requestheader - Despite high severity, actual vulnerable apps likely very rare
Exploit Demonstration
- Demo app with admin route protected by middleware cookie check
- Normal request to
/adminredirects to/unauthwithoutisadmincookie - Exploit: Adding header
x-middleware-subrequest: middlewarebypasses middleware entirely - Allows direct access to protected content without authentication
Vercel's Major Mistakes
- Terrible naming: "Middleware" misleads users coming from other frameworks
- Next.js middleware ≠ traditional middleware (Express, Laravel, etc.)
- Should be named "route interceptor" or similar
- Runs before Node.js, not part of Node runtime
- Documentation problems: Listed "authentication and authorization" as middleware use cases
- Lee Robinson quickly removed this section after being called out
- Bullet point lists include non-recommended use cases
- Poor timing: Full company offsite during incident response
- Template mistake: Disclosure included firewall product ad from previous template
What Next.js Middleware Actually Is
- Glorified switch statement for routing decisions
- Runs in edge runtime, not Node.js
- Designed for quick routing changes (redirects/rewrites)
- Good for: localization, A/B testing, simple redirects
- NOT for: authentication, database calls, data protection
- Meant to avoid spinning up full Next.js app for simple routing
Authentication Best Practices
- Don't rely solely on middleware for auth
- Use data access layer pattern with proper auth checks
- Check permissions at component/API level, not just routing level
- TRPC example: protected procedures with session validation
- Any auth function call outside middleware.ts solves this problem
Technical Analysis
- Header exists to prevent middleware recursion loops
- Internal API calls need to skip middleware to avoid infinite redirects
- Exploit hijacks this internal functionality externally
- Most real apps have additional auth layers beyond middleware
Industry Response
- Clerk initially claimed unaffected, later corrected
- Cloudflare's fix broke other middleware functionality
- Many viral posts from people who don't use Next.js
- Security researchers misunderstood Next.js architecture
Vercel's Response Timeline
- Feb 27: Initial vulnerability report (old version)
- March 1: Updated report for all versions
- March 11: Vercel confirmed vulnerability
- Within 24 hours of understanding: Patch released
- Confusion due to report being updated rather than new submission
Layout Security Issue
- Additional vulnerability: auth checks in layouts can be bypassed
- Request hierarchy: middleware → root layout → nested layouts → page
- Possible to desync layout auth and page access
- Vercel recommends no auth checks in layouts
Vercel's Remediation Plan
- Partner mailing list for private disclosures
- Consolidated security reporting through GitHub
- Improved response runbooks
- Long-term support (LTS) policy implementation
- Security assessment of middleware
- New forbidden() helpers (experimental)
Author's Recommendations to Vercel
- Jump on CVEs immediately
- Stop using misleading names (middleware, use client/server)
- Audit all documentation bullet points
- Market Next.js as primitives, not complete framework
- Emphasize Next.js ≠ Laravel/Rails comparison
Conclusion
- Vercel made preventable communication mistakes
- Actual vulnerable apps likely extremely rare
- Most outrage from people who don't understand Next.js
- Proper auth patterns would have prevented this issue
- Ratio of affected users to brand damage is "absurd"
