fix: enforce blockHosts on the browser network path in Chrome - #34788
Open
AtofStryker wants to merge 1 commit into
Open
fix: enforce blockHosts on the browser network path in Chrome#34788AtofStryker wants to merge 1 commit into
blockHosts on the browser network path in Chrome#34788AtofStryker wants to merge 1 commit into
Conversation
The synthetic response used on the CDP Fetch path auto-destroys after end(), so a 503 written by the blocked-hosts policy read as a browser cancel. The pipeline threw and the transport released the paused request untouched, so blocked hosts loaded from the real origin. Only treat a response destroyed before it finished as a cancel. Run the blockHosts system specs on Chrome as well as Electron; they were skipped in the system-tests-chrome job. Closes #34785 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
blockHosts on the browser network path in Chrome
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.
Additional details
blockHostswas silently ignored on the browser network (CDP Fetch) path in Chrome, Chromium, and Edge. The blocked-hosts policy matched and wrote a503, but the pipeline then threw it away.The synthetic response used on that path is a Node
Writable. AWritableauto-destroys afterend(), so a response a middleware finished itself read asdestroyed.createLegacyProxyPipelinetreats a destroyed response as a browser cancel and throws. The CDP transport catches that and releases the paused request untouched, so the blocked script loaded from the real origin. A realhttp.ServerResponsenever setsdestroyedonend(), which is why the MITM path was unaffected. The unload redirect (RedirectToClientRouteIfUnloaded) hit the same bug.The fix narrows the cancel check to "destroyed before finished".
forceNetworkErrorstill works, since net-stubbing destroys the response without finishing it.Why CI missed it:
block_hosts_spec.jsandblock_hosts_override_spec.jspassed nobrowseroption, sosystemTests.execskipped them wheneverBROWSERwas set. Thesystem-tests-chromejob reported them as pending and they only ever ran on Electron. Both specs now run on Chrome and Electron. Against the old check, the Chrome run fails withexpected 200 to equal 0.Steps to test
blockHosts works!and the spec should pass.yarn workspace @packages/proxy test -- test/unit/http/index.spec.ts— the new test fails if thewritableFinishedguard is removed.yarn workspace @tooling/system-tests test block_hosts— runs both specs on Chrome and Electron.How has the user experience changed?
Requests to a
blockHostshost fail with a503again in Chrome, Chromium, and Edge. No visual change.PR Tasks
cypress-documentation?type definitions?Note
Medium Risk
Touches core HTTP interception/cancel logic on the CDP Fetch path; incorrect handling could still leak blocked requests or break cancel/
forceNetworkErrorbehavior, but scope is a narrow guard with targeted tests.Overview
Fixes a 16.0.0 regression where
blockHostsdid not block traffic in Chrome, Chromium, and Edge: blocked requests could still hit the network and load scripts/resources instead of failing with 503.On the native browser network (CDP Fetch) path, request middleware ends the client response on a synthetic
Writablethat auto-destroys afterend().createLegacyProxyPipelinetreated anydestroyedresponse as a browser cancel, threw, and the CDP layer released the paused request to the origin—discarding the blocked-host 503 (same class of bug as unload redirects). The change only skips response middleware when the response is destroyed and notwritableFinished, so finished synthetic responses (blocked host, redirect) complete normally;forceNetworkErrorbehavior is unchanged.Adds a unit test for middleware that ends with 503, updates blockHosts system tests to run on Chrome and Electron (they previously skipped Chrome when
BROWSERwas set), and documents the fix in the changelog.Reviewed by Cursor Bugbot for commit 034c010. Bugbot is set up for automated code reviews on this repo. Configure here.