Skip to content

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tusharpandey13
Copy link
Contributor

@tusharpandey13 tusharpandey13 commented Apr 30, 2025

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.

@tusharpandey13 tusharpandey13 requested a review from a team as a code owner April 30, 2025 09:37
@tusharpandey13 tusharpandey13 changed the title feature/combining middleware doc Update middleware combination example to prevent unintended backend execution Apr 30, 2025
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.05%. Comparing base (c44432c) to head (bc9b5c1).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2076   +/-   ##
=======================================
  Coverage   82.05%   82.05%           
=======================================
  Files          21       21           
  Lines        1967     1967           
  Branches      343      343           
=======================================
  Hits         1614     1614           
  Misses        347      347           
  Partials        6        6           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants