Repository navigation
fix(engine): restricted downloads apply the capture proxy's address rule - #7839
Conversation
With PRODUCER_RESTRICT_PAGE_NETWORK on, remote asset downloads now go through the same transport and host check as the render page's capture proxy: - An IPv6 literal host, or a name the capture proxy refuses, is not permitted, on the first request and on every redirect hop. - Names resolve to IPv4 answers only, every answer must be public, and the download dials the checked address. A name with only IPv6 answers does not download, as in the capture proxy. - Proxy variables (HTTPS_PROXY, NO_PROXY) are not used in this mode, so no host is dialled without the address check. HYPERFRAMES_CAPTURE_PROXY still routes downloads, as it does for the page. With the setting off, downloads keep the existing transport.
…pture resolver The capture transport refuses any compressed response and sends no User-Agent, and its socket and parse errors were not retried. Restricted downloads now use the same undici agent as before, with a connect lookup that calls the capture proxy's resolvePublicAddress: IPv4 answers only, every answer public, and the checked address is the one dialled. This keeps the old request headers (User-Agent, Accept: */*), gzip, br and deflate unpacking for text fetches under the existing byte cap, the asset path's refusal of compressed bodies, "fetch failed" retry handling, and connection reuse. Non-public destinations stay non-retryable refusals.
jrusso1020
left a comment
There was a problem hiding this comment.
Reviewed at 83c6b02894b9944c3a844ea1ca044ea326118c86.
Need: yes · Size: ok · Reuse: capture resolver and existing Undici transport · Simpler: already minimal · Structure: fine (checked shared resolver and all downloader entrypoints; no split)
Risk: medium — changes address selection for restricted asset downloads.
No introduced blocker found. The checked address is passed to the socket lookup in both callback shapes; redirects remain manual and use the same policy. Restriction-off transport selection is unchanged.
Validation: full build passed; the downloader/restricted-network/public-network suites passed 163 tests, plus 5 additional controls for operator ranges, mixed address answers and hostname redirects. Restoring the base downloader makes 8 of the 15 new tests fail. Real Node 22.22.3 CDN, cross-host HTTPS redirect and gzip downloads passed with an unusable environment/global proxy configured. All four observed TLS peers matched the resolver's checked addresses, with one resolution per host.
Pre-existing follow-up: packages/engine/src/utils/urlDownloader.ts:499 relies on custom Undici lookup support that the Bun 1.4.4 probe did not invoke. Confirmed on both base and head; the Cloud Run image runs that version (packages/gcp-cloud-run/Dockerfile:223). This PR improves the Node transport but does not establish the same resolved-address protection under Bun. Follow up with a Bun-compatible pinned transport and a real-runtime connection regression test. This is not a newly introduced failure.
Not tested on dev or a deployed render host: local suites, mutation checks and live public HTTPS downloads instead.
Verdict: APPROVE
Reasoning: The Node fix and unchanged off-mode behavior check out. The reproduced Bun limitation predates this patch and remains an explicit follow-up.
— Rames
Edit accuracy: accurate 267 (base branch 267), smooth 88 of thoseThe gate passes. Quarantined, measured but not gated (8)
Unstable (1)
|
* chore: release v0.9.53 * chore: release v0.9.53 notes include heygen-com#7836 and heygen-com#7839 * chore: release v0.9.53 notes include heygen-com#7840 and heygen-com#7843
What
With
PRODUCER_RESTRICT_PAGE_NETWORKon, the render asset downloader now applies the capture proxy's address rule:HTTPS_PROXYplusNODE_USE_ENV_PROXY) orNO_PROXYis configured.With the setting off, nothing changes.
Why
The downloader and the capture proxy share the non-public rule, but they disagreed. The proxy refuses IPv6, while the downloader let through any IPv6 address outside a short deny-list. In env-proxy mode the downloader also used global
fetchwith no resolved-address check. That check ignoresNO_PROXY, so matching hosts were dialled directly without one. Compile-time asset downloads run in Node on the render host, outside the browser's proxy.Related work
Refs #7758 and #7789 (the public-only capture proxy and its address rule). The proxy's code is reused, not edited. #7827 and #7838 merge cleanly with this.
How
utils/urlDownloader.ts: when restricted, every download uses the undici agent, whoselookupcalls the capture proxy'sresolvePublicAddress. The explicit dispatcher overrides any env proxy or global dispatcher, and undici dials the address thatlookupreturned, with no second resolution. Everything that undici's transport did before is kept:Accept: */*;main;[v6]literals are refused even where undici skipslookup.A name with both A and AAAA records downloads over its checked IPv4 address, as the capture proxy does. Refusing those would break most CDNs.
Test plan
Unit tests added/updated
Manual testing performed
Documentation updated (if applicable)
Comments follow CONTRIBUTING.md "Comments": they say why, not what, and a bug fix says what the code must do and how to reproduce the bug
The new
urlDownloader.restrictedNetwork.test.tsruns real undici against a local server. 8 of its 15 cases fail onmain, including all 5 security cases:https://[2606:4700:4700::1111]/literal;NO_PROXYmatch, on a name that resolves to 10.1.2.3.Other cases cover the headers, gzip text unpacking, refusing an over-cap gzip bomb, and retrying a gzip-encoded 5xx.
The downloader and
publicNetworktests pass (132 in the touched files). Engine typecheck, the comment ratchet andverify:packed-manifestspass.A second review checked undici 7.30.1 with
NODE_USE_ENV_PROXY=1,HTTPS_PROXYand a globalEnvHttpProxyAgent. The explicit dispatcher wins, andlookupruns once, with that address dialled.Known gap: an IPv6-only name fails with a DNS error rather than a non-public refusal, so it is retried once before failing. No socket opens either time.
Not run: a live download on a render host. The tests mock the connector, so they don't check which address is dialled.