-
Notifications
You must be signed in to change notification settings - Fork 426
Update middleware combination example to prevent unintended backend execution #2076
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
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2076 +/- ##
=======================================
Coverage 82.25% 82.25%
=======================================
Files 21 21
Lines 1989 1989
Branches 348 348
=======================================
Hits 1636 1636
Misses 347 347
Partials 6 6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add some links to the explaination of this behavior in Next.js, both in the PR and EXAMPLES.md?
Merge branch 'feature/combining-middleware-doc' of https://github.com/auth0/nextjs-auth0 into feature/combining-middleware-doc
no external references exist for this vuln.
Overview
The existing documentation example in EXAMPLES.md for combining middleware advised copying all headers from the auth0.middleware response (authResponse) to the final response. This includes the x-middleware-next header, which Next.js uses as a signal to always forward the request to the backend application, regardless of the middleware's response status (e.g., 401 Unauthorized).
This behavior leads to a vulnerability where even if custom middleware logic correctly identifies an unauthenticated user and attempts to block the request with a 401 response, the presence of the copied x-middleware-next header causes Next.js to still execute the backend route handler. This could expose page data or allow unintended execution of backend logic for unauthenticated users.
Changes
This PR updates the EXAMPLES.md file to mitigate this issue:
Added a warning block and code sample.