Skip to content

fix(producer): fetch only compiler-named GSAP files from the mirror - #9233

Merged
michaelwang11394 merged 3 commits into
mainfrom
harden-gsap-mirror-fetch
Dec 2, 2026
Merged

michaelwang11394 merged 3 commits into
mainfrom
harden-gsap-mirror-fetch

Conversation

@michaelwang11394

@michaelwang11394 michaelwang11394 commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

What

Limits which script URLs skip the public-address checks when a render inlines scripts from the operator's GSAP mirror (HYPERFRAMES_GSAP_BASE_URL).

Why

Any composition script URL that started with the mirror prefix was fetched with a plain Node fetch, skipping the address checks every other composition URL gets. Only the GSAP files the compiler itself names under the mirror need that exemption. The exempt download also read the whole body before checking the 16 MiB limit, and it ignored PRODUCER_RESTRICT_PAGE_NETWORK.

Related work

None.

How

  • isOperatorMirrorGsapUrl accepts only <mirror>/gsap@<numeric version>/dist/<plain file name>.js, with no query, fragment, percent-encoding or backslash. Every other URL, including other paths on the mirror, goes through fetchPublicHttpsBytes.
  • The mirror body is read as a stream and stops at 16 MiB, the same cap the checked path uses.
  • With PRODUCER_RESTRICT_PAGE_NETWORK on, the mirror gets the same checks as any other URL. A loopback or private mirror is refused with a one-time warning, and the host's bundled GSAP is used where it has one.
  • docs/packages/studio-server.mdx describes this.
  • scripts/package-size-budgets.json: the producer's unpacked budget goes from 3,800,000 to 3,900,000 bytes. The URL matcher and the streaming size cap added about 4.8 KB over the 1% tolerance. Nothing else was added to the tarball.

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

  • bun test src/services/htmlCompiler.test.ts in packages/producer: 210 of 210 pass. The new tests show that other paths under a loopback mirror are never requested by Node. They also cover the streaming size cap, restricted mode and the URL matcher.

  • The producer typecheck, oxlint, oxfmt and the pre-commit hooks pass.

… mirror

Script inlining used to skip the public-address checks for any URL under
HYPERFRAMES_GSAP_BASE_URL. Now only gsap@<version>/dist/<file>.js URLs with
no query, fragment or percent-encoding skip them; every other URL goes through
the checked downloader. Mirror bodies are capped at 16 MiB while streaming,
and a restricted render network applies the public-address checks to the
mirror too.
@mintlify

mintlify Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
hyperframes 🟢 Ready View Preview Dec 2, 2026, 1:12 AM

💡 Tip: Enable Automations to automatically generate PRs for you.

@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 275 (base branch 275), smooth 90 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 (0)

@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.

Approve. No blockers. There is one should-fix (the docs make a claim the code doesn't do) and two nits.

What I checked

  • The mirror exemption is tight (isOperatorMirrorGsapUrl, htmlCompiler.ts:1689):
    • A raw ?, #, % or \ is refused before the URL is parsed.
    • The full normalized URL, from the scheme on, must start with <mirror>/. A user@host trick, a lookalike host or a different port all fail this check.
    • The parser has already removed any .. before the regex at :1686 runs. That regex allows exactly one file-name segment under gsap@<n>/dist/.
    • Redirects are refused (redirect: "error").
  • The size cap counts streamed, decoded bytes (readCappedBody, :1711). Content-Length is only an early reject. On overflow and on a non-OK status the reader is cancelled, and the 15 s timeout covers reading the body. I tested this against a real local server:
    • A gzip bomb (64 KiB on the wire, 64 MiB decoded, chunked, no Content-Length) was refused at 16 MiB.
    • A 40 MiB chunked body was cut off after 22 MiB had been sent.
  • Restricted mode got stricter. A mirror in restricted mode used to skip the egress and public-address checks. Now it goes through both.
  • No other fetch sites were missed. The other places that load GSAP are:
    • fetchPublicHttpsBytes, the checked path.
    • gsapVendor.ts and bundledScripts.ts, which read local files only.
    • Studio preview and the engine's in-page fetch, which load scripts in the browser, not in Node.
  • The size budget bump is justified. Measured with npm pack --dry-run, base d1b98a94 is 3,836,844 B unpacked, already at the 1% line. Head is 3,843,241 B (+6.4 KB). The new matcher is bundled into four entry points (index, public-server, compileWorker, distributed). The new 3.9M budget leaves about 1.5% headroom, and the packed size is still under its unchanged budget.

Should-fix: the "host's bundled GSAP is used" fallback never fires for a mirror URL. The new paragraph in docs/packages/studio-server.mdx:176 and the PR body both say a refused loopback or private mirror falls back to the host's bundled GSAP. But bundledScript() only matches DEFAULT_CDN_GSAP_3 (bundledScripts.ts:8), which is the https://cdn.jsdelivr.net/npm/gsap@3.x.y/dist/… pattern only. Here is what breaks:

  1. Set PRODUCER_RESTRICT_PAGE_NETWORK=true with HYPERFRAMES_GSAP_BASE_URL=http://127.0.0.1:….
  2. The compiler rewrites a GSAP reference it can't resolve to point at the mirror.
  3. The fetch is refused and no stand-in matches, so the tag stays external.
  4. The restricted page can't load the external tag either, so the render has no GSAP.

I reproduced this with HYPERFRAMES_GSAP_VENDOR_DIR set: the mirror URL stayed un-inlined, while the jsDelivr URL in the same run was inlined. This fails closed, so it is safe, but before this PR that configuration rendered. You could fix it either way:

  • Have the stand-in also recognise <mirror>/gsap@3.x.y/dist/<Name>.min.js.
  • Correct the docs and PR body to say GSAP is lost in that setup.

Nits

  • "Compiler-named" covers less than the compiler can write. rewriteUnresolvableGsapToCdn (htmlTagScans.ts:85-94) copies whatever follows /dist/, so vendor/gsap/dist/esm/gsap.js or …/gsap.min.js?v=2 becomes a mirror URL that the regex refuses. On a public mirror those URLs still load through the checked path. On a loopback or private mirror they now fail. That is a safe-direction regression, and one sentence in the PR body would cover it.
  • Some cases are untested. No test pins the user@host URL trick, a plain ../ traversal, or a gzip response. I checked all three by hand and they behave correctly.

Tests

  • htmlCompiler.test.ts: 210 pass.
  • bundledScripts.test.ts: 8 pass.
  • htmlCompiler.remoteFetchBounds.test.ts: 8 pass.
  • Mutants: 3 of 3 caught.
    • Matcher made to always return true: caught by "never requests other paths under a loopback mirror".
    • arrayBuffer() followed by a size check, instead of the streamed cap: caught by the size-limit test.
    • The mirrorExemptionAllowed() gate removed: caught by the restricted-mode test.

Need ✅ · Size ✅ (budget bump measured) · Reuse ✅ · Simpler ✅ · Structure ✅
Risk: low. The changes are strictly tighter, and the one regression fails closed. Fix the docs claim.

Review by Rames

@michaelwang11394
michaelwang11394 added this pull request to the merge queue Dec 2, 2026
Merged via the queue into main with commit f23bb51 Dec 2, 2026
103 of 104 checks passed
@michaelwang11394
michaelwang11394 deleted the harden-gsap-mirror-fetch branch December 2, 2026 02:06
@miguel-heygen miguel-heygen mentioned this pull request Dec 2, 2026
4 of 5 tasks
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