Repository navigation
fix(cli): preview answers unknown paths with an inert refusal, not the Studio shell - #8161
Conversation
Edit accuracy: accurate 271 (base branch 271), smooth 73 of thoseThe gate passes. Quarantined, measured but not gated (0) |
jrusso1020
left a comment
There was a problem hiding this comment.
Reviewed at 9910e9eb15df4b6d4ed8c037fea02622d7ad4f4d.
studioServer.ts:998 rejects code/state queries before all routes, including project preview and non-GET requests. The shell now has only its two entry routes; the fixed refusal never reflects request input. The CSP sandbox supplies opaque-origin protection in addition to framing denial and COOP. The legitimate login listener is a separate server and remains unchanged.
Validation: full workspace build passed. Through pytest-gate.sh, the unknown-path, static-asset, file-race and auth tests passed 268/268. Replacing only studioServer.ts with its base version gives 13 failures / 3 passes in the 16 new regressions. Restored afterward. Independent adversarial source audit found no blocker. Preview was tested through its actual Hono app; I did not run a live preview/browser login flow.
Nit: after the play/present change lands, consolidate server/inertRefusal.ts and utils/strayRequestRefusal.ts into one shared query predicate/header policy, preserving the intentionally different status/body contracts. They currently duplicate the same security policy.
Need: yes · Size: ok · Reuse: existing Hono boundary and URLSearchParams · Simpler: focused entry-route allowlist · Structure: consolidate sibling refusal helpers after both land
Risk: medium — local browser security boundary.
Verdict: APPROVE
Reasoning: Query-bearing returns cannot reach project code, unknown paths no longer remount the shell, and legitimate entry/login tests remain green. This is the query-return mitigation, not general origin separation.
— Rames / hf-review
miguel-heygen
left a comment
There was a problem hiding this comment.
Review at 9910e9eb, against main (merge base 7930525; merges clean with current main ed3f05a and with #8160). Rames already covered the server-side behavior and the helper duplication; this adds a browser run and the one preview mode the fix doesn't reach.
What holds up
studioServer.ts:999runs before every other middleware and route, socode/stateis refused on every path and method,/api/*included. I sent 23 request variants through the app:/index.html?code=,/?code=,/oauth/callback/?code=,%63ode, a bare?code, a duplicatecode,//oauth/callback?code=,/assets/../oauth/callback?code=,/assets/x.js?code=,/__hyperframes_config?code=,/api/runtime.js?code=,/api/projects/project/preview/index.html?state=, and HEAD and OPTIONS. Every one got the inert 400 with the full header set and a fixed body, and none echoed the request.%2563ode,CODEanda=1;code=still get the shell, but the authorization server always writes a literalcode=key, so none of those can carry a real return.- I ran it in Chrome 155 against a real server. The attacker page was the project's own preview document (
/api/projects/project/preview). Iframe and popup, direct and through a cross-origin 302, to/oauth/callback,/,/index.htmland the project preview path. Onmainall 12 reads returned…?code=SECRET. On this head every popup isseveredand every frame isunreadable. The PR body says no browser run was done, so this fills that gap. inertRefusal.ts:2-11:sandboxis the part that matters. COOP alone leaves a same-origin popup readable, and the comment says so. The tests pinsandbox, nosniff andframe-ancestors 'none'(studioServer.unknownPaths.test.ts:57-75), so dropping one of them fails CI.- The claim that 13 of 16 tests fail on
mainholds. Withmain'sstudioServer.tsswapped in, I get 13 failed and 3 passed. serviceWorker.register('/api/projects/project/preview/sw.js')from project script is refused (createStudioApi→refuseServiceWorkerScripts). So a worker can't sit in front of a project path and catch the return before this middleware sees it.- Studio routes by hash only (
useStudioUrlState.ts:92,useServerConnection.ts:64). Nothing in studio, studio-server, core or player builds acodeorstatequery, so serving the shell only at/and/index.htmlbreaks no Studio link.
Blockers
- Rule 2:
previewstill serves the Studio shell at/oauth/callback?code=…in its two Vite modes.preview.ts:591(dev mode: CLI run from source,env.ts:5-8) andpreview.ts:607(local mode: the CLI's own@hyperframes/studio, orHYPERFRAMES_LOCAL_STUDIO=1,preview.ts:1567) both start the Vite server frompackages/studio/vite.config.ts. That server uses Vite's default SPA fallback (vite.config.ts:388, noappType), anddevProjectApionly guards/api/*and/__hyperframes_config(vite.config.ts:225). I ranvitefrom this head and fetchedGET /oauth/callback?code=SECRET&state=sandGET /?code=SECRET. Both returned200 text/html, the Studio shell, with no COOP and no sandbox.- Failure scenario: someone running the CLI from a monorepo checkout (HeyGen engineers, whose sessions are worth the most) runs
previewon an untrusted project. Project script on the Vite origin opensapp.heygen.com/oauth/authorizein a popup, with its own PKCE challenge andredirect_uri=http://127.0.0.1:<vite port>/oauth/callback. The backend accepts any loopback port and path for a public client (experiment-frameworkdb/droplet/oauth2_models.py:69,:580-583). The authorize page sends no COOP and onlyframe-ancestors(checked live), so the opener keeps its handle and readspopup.location.hrefonce the redirect lands on the shell. - The published npm CLI always runs embedded mode, so end users are covered. Fix: register the same refusal as the first
server.middlewares.useindevProjectApi. It can reusecarriesOAuthReturnand the headers. Alternatively, descope it in the body with a tracked follow-up. The body's claim thatpreviewserves the shell only at/and/index.htmldoesn't hold in those two modes.
- Failure scenario: someone running the CLI from a monorepo checkout (HeyGen engineers, whose sessions are worth the most) runs
Nits
- Building on Rames's consolidation nit: the two copies have already drifted. This one adds
Cross-Origin-Resource-Policy: same-originand answers 400. The #8160 copy (utils/strayRequestRefusal.ts:6-14) has no CORP and answers 404. One shared header constant would keep the policy from drifting further. - The body says any other path gets the plain-text inert 404. That's true at the top level, but under
/api/*the sub-app answers itself:/api/nopeis atext/plain404 with no sandbox, and a missing project file is a JSON 404. Neither carries a return, so this is wording only. - Residual, not this PR's to fix, but worth one line in the body as #8160 has: a return in the fragment (
/#code=) never reaches the server. In Chrome,/#code=and/api/projects/project/preview/index.html#code=stay readable on this head. The code grant always answers in the query, but the backend still registers the implicit grant while its strict gate is off (heygen/domain/auth/logic/oauth2_server.py:191). Whether that can reach these servers depends on the CLI client's allowed response types, which is part 4's to close. - Tests: HEAD, OPTIONS, a trailing slash and a duplicate key behave correctly (above), but none of them is pinned. A browser regression like #8160's
oauthReturn.browser.test.tswould pin the opaque-origin result the headers exist for.
CI: every required check passes at 9910e9eb (Build, Typecheck, Test, regression, Test: runtime contract, Test reachability, Render on windows-latest, Tests on windows-latest, Studio and player captures, Studio: edit accuracy gate, Semantic PR title). Skills: manifest in sync was skipped. The only pending check is the draft-mode WIP check.
Verdict: REQUEST CHANGES
Reasoning: The embedded preview fix is correct and holds in Chrome: all 12 query-return reads that succeed on main are blocked here. But preview's Vite-served dev and local modes still hand the shell to /oauth/callback?code=, with no COOP or sandbox. Cover them with the same middleware, or explicitly descope them with a ticket, and this is an approve.
|
@miguel-heygen thanks. I addressed the blocker in
Tests at 🤖 Addressed by Claude Code |
jrusso1020
left a comment
There was a problem hiding this comment.
Reviewed at c8c0ac8b483cec3dc6b6ba264c8772de1fcd3fca.
Re-review of the delta from 9910e9eb. The Vite-mode gap raised by @miguel-heygen is resolved: both source-dev and local-Studio launch paths use this config, and its first middleware refuses query returns before API/runtime/config handlers and Vite's SPA fallback. Embedded preview retains the same fixed body and security headers through the shared studio-server helper. The Vite source import and built CLI export both resolve correctly.
Validation: bun run build passed. Through pytest-gate.sh, Studio's vite.config.hosts.test.ts passed 12/12, and CLI unknown-path/static-asset/auth tests passed 250/250. Removing only the new Vite middleware makes all five new refusal cases fail (5 failed, 7 passed); restoring it passes 12/12. A real Vite server also passed 24 HTTP refusal probes across GET/HEAD/OPTIONS/POST, including encoded keys, repeated/empty values, API and asset paths, plus a successful ordinary shell control. The server emitted dependency-scan cancellation messages during intentional shutdown, after the assertions passed. No live OAuth or browser popup flow was run in this round. Independent adversarial source audit found no introduced blocker.
The existing follow-up to consolidate play/present's refusal remains appropriate. Fragment-only returns remain outside this server-side query mitigation.
Need: yes · Size: ok · Reuse: shared studio-server refusal and existing response bridge · Simpler: already minimal · Structure: fine (checked embedded and Vite boundaries; shared policy removes duplication)
Risk: medium — local browser security boundary.
Verdict: APPROVE
Reasoning: The previously uncovered Vite launch modes now enforce the same query-return boundary, and the regression demonstrably fails without that middleware.
— Rames / hf-review
miguel-heygen
left a comment
There was a problem hiding this comment.
Re-review at c8c0ac8b, against main. This follows my change request at 9910e9eb. The one commit since then covers the blocker, and Rames has approved at this head.
What changed and holds up
- Both Vite modes now refuse a return.
devProjectApiregisters the refusal as its firstserver.middlewares.use(packages/studio/vite.config.ts:224-228). PluginconfigureServermiddleware runs before Vite's own stack, so a request carryingcodeorstategets the inert 400 before the host check,/api/*,/__hyperframes_configand the SPA fallback.devProjectApiis the only plugin here that adds middleware (vite.config.ts:364). - One helper, no drift between the two servers.
studio-server/src/helpers/inertRefusal.tsnow holds the headers,carriesOAuthReturnandrefuseOAuthReturn. The embedded server (studioServer.ts:1001-1003) and the Vite config both import it, and the CLI's own copy is gone. Local mode needsvite.config.tson disk (preview.ts:1566), and the published@hyperframes/studioships onlysrcanddist, so the relative import into../studio-server/srcalways resolves where that config runs. That's the same pattern as the existingrequestIdentityimport. - Pinned.
vite.config.hosts.test.tssends five returns (/oauth/callback,/callback,/,/index.html?state=, a project preview path) through the plugin's middlewares, and asserts the 400 status,sandbox,frame-ancestors 'none', COOP, nosniff and no echo. A plain entry request still passes to Vite. Rames reports five failures with the middleware removed.
Nits (carried over, not blocking)
- The #8160 copy (
utils/strayRequestRefusal.ts) still answers 404 with no CORP. Pointing it at this helper would finish the consolidation. - A return in the fragment never reaches either server. Closing that is part 4's job.
Not run locally: the tests and a live Vite run at this head. I ran Vite at 9910e9eb to find the gap, and the new tests pin the fix.
CI: At c8c0ac8b, all 57 checks that ran pass, including Build, Typecheck, Test (cli, studio, runtime), regression, the Windows suites, Studio edit accuracy and CodeQL. 12 are skipped by path, and none fails or is pending. It merges cleanly into the current main.
Verdict: APPROVE
Reasoning: The Vite-served dev and local modes now refuse a query return through the same helper as the embedded server, ahead of the SPA fallback, and a test pins the headers. That clears the one blocker from my last review.
miguel-heygen
left a comment
There was a problem hiding this comment.
Requesting changes; details sent to you directly.
…e Studio shell Studio routes by location.hash only, yet the preview server answered every unknown GET with the Studio shell (200, same origin, query kept). An OAuth redirect to the preview port (/oauth/callback?code=...&state=...) therefore re-mounted the project, and project script read the code from the address. The shell is now served only at / and /index.html. Any other path gets a plain-text 404, and a request carrying `code` or `state` at any path (entry and preview routes included) gets a plain-text 400. Both carry a sandbox CSP (opaque origin), COOP same-origin, frame-ancestors 'none' / X-Frame-Options DENY, nosniff, no-referrer and no-store, and never echo the request. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`preview` from a source checkout (dev mode) and with the local studio (HYPERFRAMES_LOCAL_STUDIO=1) run packages/studio/vite.config.ts, whose SPA fallback served the Studio shell at /oauth/callback?code=... with no COOP or sandbox. devProjectApi now refuses a `code` or `state` at any path as its first middleware, with the same inert response as the embedded server. The refusal moves to @hyperframes/studio-server so both servers share one helper. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
c8c0ac8 to
966e802
Compare
jerry-heygen
left a comment
There was a problem hiding this comment.
Re-approval at 966e802239cb4472ea057e5fee119dfb475c3623.
What I checked first-hand:
- The eight changed files, compared file by file between the previously approved head
c8c0ac8band this head, differ in five comment lines only (the internal ticket id removed from each). No code, test or config line differs. - The PR title, description and both commit messages at this head carry no internal ticket id.
- I read the PR's own diff against
main: the refusal runs as the first middleware before every route, the shell is served only at/and/index.html, every other path ends in the fixed plain-text 404, and the refusal body never reflects request input. That matches what the two earlier approvals atc8c0ac8bdescribe. - Workflow runs at this head: CI, CodeQL, regression, preview-regression, Windows render verification, Player perf and Comments completed with success. One
PR capturesrun shows cancelled next to a successful one of the same name.
Not checked by me: nothing was run (no browser, no local server); I did not re-derive the earlier reviewers' browser findings.
Two things for the author: the PR is still marked draft, so it cannot merge until it is marked ready; and the earlier request for changes on the ticket ids shows as dismissed, so its author may want to confirm the wording at this head.
This is a technical re-approval of an unchanged change; the merge is the author's and the repo owners' step.
— Jerrai (cutroom-dev)
What
hyperframes previewanswered every unknown GET with the Studio shell (200, same origin, query kept). An OAuth redirect to the preview port (/oauth/callback?code=…&state=…) therefore re-mounted the project, and project script read the code from the address.Studio routes by
location.hashonly, so it never needs a path:/and/index.html./assets/*,/icons/*,/favicon.svg,/api/*and/__hyperframes_configare unchanged.404 Not found..codeorstateat any path gets a plain-text400. That includes/and/api/projects/:id/preview, which loads project script. This runs as the first middleware. No Studio route uses either parameter.HYPERFRAMES_LOCAL_STUDIO=1) runpackages/studio/vite.config.ts, whose SPA fallback also served the shell at/oauth/callback?code=….devProjectApinow refuses acodeorstateat any path as its first middleware, before every route and Vite's own fallback. Unknown paths there still reach Vite, which serves source modules at many paths, so these modes get the OAuth-return refusal but no path allowlist./api/*the API sub-app answers unknown paths itself (a plain-text or JSON 404, no sandbox). No return reaches it, because thecode/staterefusal runs first.Content-Type: text/plain,X-Content-Type-Options: nosniff, a CSP ofsandbox; default-src 'none'; frame-ancestors 'none',X-Frame-Options: DENY,Cross-Origin-Opener-Policy: same-origin,Cross-Origin-Resource-Policy: same-origin,Referrer-Policy: no-referrer,Cache-Control: no-store. The CSPsandboxgives the page an opaque origin, so a same-origin opener or parent cannot read its address. COOP alone leaves a same-origin popup readable. The helper now lives in@hyperframes/studio-server(helpers/inertRefusal.ts), so the embedded server and the Vite modes share it. The part 3 copy in fix(cli): play and present answer unknown paths with an inert refusal #8160 (utils/strayRequestRefusal.ts) has already drifted: it answers 404 and sends no CORP. Follow-up: once both PRs land, move fix(cli): play and present answer unknown paths with an inert refusal #8160 onto this helper so the header set has one owner.The CLI's own login (
packages/cli/src/auth/loopback.ts) runs its ownnode:httpserver on an ephemeral port and is untouched.src/authtests pass.No visible change
The only non-test change under
packages/studiois 6 lines invite.config.ts: a dev-server middleware that answers a request carryingcodeorstatewith a plain-text refusal. Studio's UI, its normal loads, and the player don't change.Tests
New
packages/cli/src/server/studioServer.unknownPaths.test.ts:/oauth/callbackand/callbackwithcodeandstate, on127.0.0.1andlocalhost, plus four unknown paths. Each must be non-HTML with the headers above and must not contain the code, the state,<or the shell.codeand/orstateon/,/index.htmland/api/projects/project/preview, and on a POST./,/index.htmland/?hf_canary_…still serve the shell.packages/studio/vite.config.hosts.test.ts, "studio dev server OAuth returns":/oauth/callback,/callback,/,/index.htmland/api/projects/project/preview, each withcodeorstate, must get the inert 400 from the plugin's middleware, with noSECRETin the body. A plain/?hf_canary_…must still pass through to Vite.Fails without the fix:
studioServer.unknownPaths.test.ts. 13 of 16 tests fail againstmain'sstudioServer.ts. For example, "refuses an OAuth return at /oauth/callback instead of serving the Studio shell" getsexpected 200 to be greater than or equal to 400, and the preview-route and POST cases getexpected null to be 'nosniff'. The 3 entry-route tests pass on both. Alsovite.config.hosts.test.ts"studio dev server OAuth returns": all 5 refusal cases fail without the middleware. The page routes getexpected undefined to be 400, because they pass through to Vite's fallback; the preview route getsexpected 200 to be 400.Two existing tests assumed the shell at a made-up SPA path (
/editor,/projects/demo). They now hit/index.html.Related changes (not in this PR)
play/presentis a separate PR (fix(cli): play and present answer unknown paths with an inert refusal #8160).Residual (not this PR)
A return in the fragment (
/#code=) never reaches the server, so no server-side check can refuse it. The code grant always answers in the query. Whether the CLI client can be issued an implicit-grant (fragment) response is part 4's to close.Verification
vitest runforsrc/server+src/auth: all pass, apart from the known-flakyfileWatcher.atomicreal-FS test, which passes on rerun.main'sstudioServer.tson this machine (openWritesNothingis flaky and passed with the fix):whisper/manager-resolution,utils/projectLock,utils/publishProject(Unicode form),commands/lambda/deploy(warming),checkSweep.chromium×2 (WebGL).tsc --noEmit, oxlint, oxfmt, fallow andcomment-ratchetare clean.966e80223:studio-server2154 passed; Studiovite.*89 passed; CLIsrc/server+src/auth413 passed.tscis clean forstudio-server,studioandcli, and the comment ratchet passes.4956762fwas checked by a reviewer in Chrome 155: all 12 popup and iframe reads that succeed onmainare blocked. I have not run a browser against the Vite modes; their test drives the plugin's middleware chain directly.🤖 Generated with Claude Code