Repository navigation
fix: respond with 404 to requests for unowned Cypress-reserved paths - #35162
Open
cacieprins wants to merge 3 commits into
Open
cacieprins wants to merge 3 commits into
cacieprins wants to merge 3 commits into
Conversation
Requests for /__cypress/ and /__/ paths nothing serves never receive a response, so a synchronous XHR to one freezes the renderer for good. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ware A middleware that answers without calling next() — serve-internal-routes' reserved-path 404 loop guard, its loopback failures, and loopback fulfillment — never runs the legacy pipeline, so nothing wrote ctx.res on the Express transport and the request hung with no response (#34810). The proxy HTTP codec now writes synthesized responses to the Express client when it is the transport-level codec. The synthetic (CDP) codec keeps priming its ctx from the origin response and lets the pipeline write the client response, so it does not opt into that write. Fixes #34810
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
/__/…,/__cypress/…) never receive a response #34810Additional details
A request for a path under
/__cypress/or/__/that Cypress doesn't serve never received a response. Afetch()for one hung, and a synchronousXMLHttpRequestto one froze the browser for good, because a sync XHR blocks the page until it is answered. The cause is thatserveInternalRoutescan answer with its own 404 without callingnext(), and on the Express transport only the last pipeline stage wrote the client response, so the 404 was dropped.The fix is the commit from #35077 by @VedantBhayani, cherry-picked here with its authorship intact (
c0572da28c). The Express codec now writes a response synthesized by a short-circuiting middleware to the client; the CDP codec does not. That PR is still waiting on review, and its changelog entry conflicts with other changes landing ondevelop, so this PR carries the fix forward instead. Once this merges, #35077 can be closed.What this PR adds on top:
unowned_reserved_path_spec.ts, that reproduces Synchronous XHR to a URL under the /__cypress/ namespace hangs the browser forever (15.19.0+, still present in 16.1.1 #35026 in Electron and Chrome. On unpatcheddevelopthe async fetches never settle and the run hangs until the harness timeout; with the fix all 7 tests pass. It covers asyncfetchand sync XHR to/__cypress/repro-check,/__cypress//config.js(whatlocation.pathname-derived URLs produce under/__cypress/src/...) and/__/does-not-exist, plus a control to a path outside the reserved namespaces.Not changed: Cypress still claims
/__/on any origin by pathname alone. Unowned requests now get a prompt 404 there too, but whether another origin's/__/should be claimed at all is a separate question.Note
Medium Risk
Touches core proxy response encoding for all Express-routed traffic; behavior is scoped to short-circuit responses and guarded against double-writes, but a regression could affect how middleware answers are delivered.
Overview
Fixes hung requests when the app hits Cypress-reserved URLs (
/__cypress/…,/__/…) that no handler owns. Middleware such asserveInternalRoutescould return a 404 without callingnext(), but on the Express proxy transport only the legacy pipeline normally writesctx.res, so that synthesized response was dropped and clients never got an answer (sync XHR could freeze the page).The Express HTTP codec now optionally writes short-circuit middleware responses straight to the client via
writeSynthesizedResponseandwriteSynthesizedResponses: trueonproxyHttpCodec. The CDP/synthetic codec keeps the default off so it does not double-write. Coverage includes unit tests for the codec and internal-routes stack, plus a new system test that asserts 404 for asyncfetchand sync XHR on several unowned reserved paths.Reviewed by Cursor Bugbot for commit 6bb13d2. Bugbot is set up for automated code reviews on this repo. Configure here.
Steps to test
To see it fail, check out
55aeb23a72(the test without the fix); the run hangs until the 90s timeout.How has the user experience changed?
Before: a request for an unserved
/__cypress/…or/__/…path hangs, and a synchronous XHR to one freezes the browser with no error. After: it receives a404promptly.PR Tasks
cypress-documentation?type definitions?🤖 Generated with Claude Code