AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

Middleware Redirects Drop _Rsc By Causing RSC Header Mismatch And Cache Poisoning Risk

Redirects issued from proxy.ts via NextResponse.redirect lose the `_rsc` query parameter while retaining the RSC request header, leading to an extra 307 validation redirect and potential cache poisoning when a shared cache keys on the URL.

highConfidence 75%Next.jsServer ActionsRoute HandlersAffected V16.4.0-Canary.46

Origin Analysis

NextResponse.redirect in middleware does not preserve the `_rsc` query parameter when constructing the Location URL, while the original RSC request header remains. This discrepancy triggers Next.js's internal validateRSCRequestHeaders on the subsequent request, resulting in an unnecessary second 307. Rewrites and next.config redirects already propagate `_rsc`, but middleware redirects lack this logic.
1. Run repro app in dev mode (`npm dev`). 2. Execute `curl -sI -H 'RSC: 1' 'http://localhost:3000/redirect-source?_rsc=abc123'`. 3. Observe the 307 Location header misses `_rsc` while the RSC header remains.

Fixing Code Block

Edge Case Audit

This hotfix only applies to redirects where you use the helper; existing raw `NextResponse.redirect` calls remain affected. If the redirect destination is cross-origin, do not propagate `_rsc` to avoid leaking the RSC identifier. Rolling back the code change is straightforward; no persisted state. Upstream fix may eventually make this helper unnecessary.

Ecosystem Topology

Agent Frameworks

LangChain, LlamaIndex, and Pydantic

  1. highProperty graph relation keys collide when entity IDs or labels contain underscores
  2. highCodeActAgent drops assistant tool-call metadata during handoff, leaving an orphan tool response
  3. high[Bug]: HierarchicalNodeParser async methods return the documents unsplit
  4. highLLM.predict_and_call fails with ValidationError for non-function-calling models when react_chat_formatter is omitted
  5. highAnthropic streaming server-tool input_json_delta overwrites completed client tool_use arguments due to stale cur_tool_call state