Skip to content

fix(engine): restricted downloads apply the capture proxy's address rule - #7839

Merged
michaelwang11394 merged 2 commits into
mainfrom
sec-low8e-1115
Nov 15, 2026
Merged

michaelwang11394 merged 2 commits into
mainfrom
sec-low8e-1115

Conversation

@michaelwang11394

Copy link
Copy Markdown
Contributor

What

With PRODUCER_RESTRICT_PAGE_NETWORK on, the render asset downloader now applies the capture proxy's address rule:

  • IPv6 literal hosts, and names that resolve only to IPv6, are refused before any socket opens, on the first request and on every redirect hop.
  • Every connection is dialled to an address checked by the proxy's resolver, even when an env proxy (HTTPS_PROXY plus NODE_USE_ENV_PROXY) or NO_PROXY is 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 fetch with no resolved-address check. That check ignores NO_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, whose lookup calls the capture proxy's resolvePublicAddress. The explicit dispatcher overrides any env proxy or global dispatcher, and undici dials the address that lookup returned, with no second resolution. Everything that undici's transport did before is kept:
    • its User-Agent and Accept: */*;
    • gzip, br and deflate unpacking for text, under the existing cap;
    • the asset path's refusal of compressed bodies, as on main;
    • retries on unreachable hosts, dropped connections and 5xx;
    • keep-alive.
  • The URL check also applies the proxy's host rule on every redirect hop, so [v6] literals are refused even where undici skips lookup.

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.ts runs real undici against a local server. 8 of its 15 cases fail on main, including all 5 security cases:

    • an https://[2606:4700:4700::1111]/ literal;
    • a name with only IPv6 answers;
    • a redirect hop to an IPv6 literal;
    • an env proxy with and without a NO_PROXY match, 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 publicNetwork tests pass (132 in the touched files). Engine typecheck, the comment ratchet and verify:packed-manifests pass.

  • A second review checked undici 7.30.1 with NODE_USE_ENV_PROXY=1, HTTPS_PROXY and a global EnvHttpProxyAgent. The explicit dispatcher wins, and lookup runs 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.

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 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@github-actions

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 267 (base branch 267), smooth 88 of those

The gate passes.
Smoothness is reported in the artifact, not gated. A case fails only if it fails 2 of 3 runs.

Quarantined, measured but not gated (8)

Unstable (1)

  • seqrotatenudge-none-px-r0-root-z100: tracking 0.03, pressJump 0, drop 0, reload 3.07, render 0.04, renderKey -, undo false, teleport true / tracking 0.03, pressJump 0, drop 0, reload 0, render 0.08, renderKey -, undo true, teleport true / tracking 0.03, pressJump 0, drop 0, reload 0, render 0.08, renderKey -, undo true, teleport true

@michaelwang11394
michaelwang11394 added this pull request to the merge queue Nov 15, 2026
Merged via the queue into main with commit 125a944 Nov 15, 2026
91 checks passed
@michaelwang11394
michaelwang11394 deleted the sec-low8e-1115 branch November 15, 2026 13:02
wangzheuser pushed a commit to wangzheuser/hyperframes that referenced this pull request Nov 15, 2026
* 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
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