Repository navigation
fix(cli): play and present answer unknown paths with an inert refusal - #8160
Conversation
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Automations to automatically generate PRs for you. |
Edit accuracy did not run: 0 of 15 shards reported results; see the shard jobs.Nothing was compared with the base branch. |
jrusso1020
left a comment
There was a problem hiding this comment.
Reviewed at 17510c6fe3e7725fd072a1dbdd5ab8af71f74ef3.
The refusal runs before either app's routes and replaces downstream 404 headers cleanly. Its sandbox/framing/opener policy blocks the tested same-origin reads without changing normal player/presenter routes.
Important — resolve the current main conflicts before approval. GitHub reports CONFLICTING; git merge-tree --write-tree HEAD origin/main independently identifies conflicts in packages/cli/src/commands/play.ts, present.ts and both test files. Rebase and preserve both the new app/refusal wiring and main's project-name escaping/terminal sanitization. Rerun the combined tests at that resolved head; an approval on this head would not review the security-sensitive conflict resolution.
Validation: full workspace build passed; 49 play/present unit tests passed. Chrome 155 ran both real-app browser tests successfully (iframe, redirected iframe, popup, redirected popup). Removing the refusal registration from both apps makes both browser tests fail, with all four probes reading the synthetic callback URL. Source restored. The default old system Chrome timed out during launch; no test assertions ran in that attempt. Independent adversarial source audit found no additional code blocker. Fragment delivery and origin separation remain outside this patch's stated scope.
Need: yes · Size: ok · Reuse: shared refusal middleware for both apps · Simpler: already focused · Structure: fine (checked buildPresentApp and composition middleware; extraction preserves setup)
Risk: medium — local browser security boundary with conflicting integration.
Verdict: REQUEST CHANGES
Reasoning: The mitigation passes its tests, but the current head conflicts with main in the protected paths. Resolve and re-pin so the resulting behavior can be reviewed before approval.
— Rames / hf-review
… (SECOPS-2642 part 3) An OAuth return that lands on the play or present port was a 404 document on the same origin as the composition frame, so project script could read its ?code=&state= through a frame, a popup or the authorize redirect. Unknown paths, missing composition files and any request carrying code or state now get a fixed text/plain 404 on an opaque origin (CSP sandbox) that cannot be framed and drops its opener (COOP same-origin). play's app setup moves into an exported buildPlayApp so tests can serve it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
17510c6 to
de900d5
Compare
jrusso1020
left a comment
There was a problem hiding this comment.
Reviewed at de900d59f6ddad745521afe36780733d447c3b86, rebase delta from 17510c6fe3e7725fd072a1dbdd5ab8af71f74ef3.
The prior integration blocker is resolved: GitHub reports mergeable and the local merge-tree check is clean. The range-diff preserves the refusal implementation while retaining main's HTML escaping and terminal sanitization in play/present. The test redirector now takes a fixed closure destination instead of a request parameter, addressing the CodeQL note without weakening the redirect probe.
Validation through pytest-gate.sh: 52 play/present unit tests passed, including the retained escaping regressions; both Chrome 155 browser tests passed. Removing the refusal registration again makes both browser tests fail, with all four probes reading the synthetic callback URL. Source restored. Workspace build passed; the CLI was rebuilt after restoration. Fresh independent adversarial review found no introduced blocker. This remains a query-return mitigation; origin separation is outside this patch.
Need: yes · Size: ok · Reuse: shared refusal middleware · Simpler: already focused · Structure: fine (checked app extraction and main escaping helpers; no split needed)
Risk: medium — local browser security boundary.
Verdict: APPROVE
Reasoning: The conflicts are resolved without losing either security change, and the combined response, escaping and browser regressions pass at this head.
— Rames / hf-review
miguel-heygen
left a comment
There was a problem hiding this comment.
Review at de900d59, against main. This adds to Rames's approval at this head. The rebase resolved the conflicts I found at 17510c6f. git range-diff shows commit 1 differs only where main's project-name escaping and terminal-text changes meet play.ts, present.ts and their tests, and commit 2 is unchanged. It now merges cleanly into main.
What holds up
- Order: the refusal runs before
refuseUnknownHostsin both servers (play.ts,present.ts), and the old 404s are replaced cleanly. - Variants (run at
17510c6f; the refusal code is unchanged since): I sent 19 request variants to the present app, covering a trailing slash, an encodedcodekey, a duplicate key, HEAD and OPTIONS. All got the inert answer, and none reflected anything. - The tests fail without the fix: at
17510c6f, removing it failed 13 of the 49 play/present unit tests, and the Chrome test passed 2/2 with it. Rames reports 52 unit tests and both Chrome tests pass at this head. - Service workers:
/composition/*refuses service-worker scripts. - CodeQL: the test's redirector now uses a fixed target, which answers the open-redirect note before
main's CodeQL ruleset sees it.
Nits
- The two refusal copies have drifted. This one (
utils/strayRequestRefusal.ts) answers 404 with noCross-Origin-Resource-Policy. #8161'sinertRefusal.tsanswers 400 and adds CORP. One shared header constant would stop further drift. This builds on Rames's consolidation nit. - The fragment gap is shared with #8161 and isn't fixed by either. A
#code=return never reaches the server, so/#code=and/composition/index.html#code=stay readable in Chrome. The code flow always answers in the query. But the backend still registers the implicit grant while its strict-mode flag is off (heygen/domain/auth/logic/oauth2_server.py:191in experiment-framework). Origin separation (#7846, #8142) closes this.
CI: At de900d59, all 68 checks that ran pass, including Tests on windows-latest: engine-cli-1, and none fails or is pending.
Verdict: APPROVE
Reasoning: play and present refuse every query return with an inert answer, the rebase keeps main's escaping fixes, and the browser test shows the reads blocked. What remains is shared follow-up work, not a blocker here.
What
hyperframes playandhyperframes presentnow answer two kinds of request with a fixed plain-textNot found(status 404) that no script can read:/composition/*file), andcodeorstate, on any path,/included.The response is
text/plainwithnosniff, never echoes the request, and carriesCross-Origin-Opener-Policy: same-origin, a CSP ofsandbox; default-src 'none'; frame-ancestors 'none',X-Frame-Options: DENY,Referrer-Policy: no-referrerandCache-Control: no-store. The CSPsandboxputs the document on an opaque origin, so even a same-origin opener with a matching COOP cannot read its address.play's app setup moves out ofrun()into an exportedbuildPlayApp, likepresent'sbuildPresentApp, so tests can serve the real app.Why
HeyGen's sign-in returns a CLI code to any loopback port.
playandpresentserve their page and the project's files from one origin, and the composition frame shares that origin (sandbox-origin="same-origin"stays opted in for both after #8142). Before this change, a return address that landed on their port was a 404 document on that origin. Composition script could read?code=…&state=…throughparent, using a frame, a popup, or the authorize redirect.Before choosing the headers I measured each candidate in Chrome. COOP alone is not enough: with COOP on both the refusal and the page, a same-origin popup stays in the same browsing-context group and its address is still readable. CSP
sandboxcloses that case, and a top-level visit still shows an ordinary 404.Scope and follow-ups
studioServer.ts, and (4) backend loopback consent in experiment-framework. This PR does not touchstudioServer.ts.packages/cli/src/utils/strayRequestRefusal.ts, used only by play/present for now. If the preview fix ends up with the same refusal, the two can merge into one helper afterwards.sandbox-origin="same-origin"(fix(player): a sealed player plays media from hosts without CORS and names a missing runtime #8142 keeps it on for both, because the slideshow controls media, mute and keys through the frame) or move to Studio's sealed preview with frame tokens (feat(studio): Studio's preview runs sealed by default #7846). I'd do that after both of those land, not in parallel./#code=…) never reaches the server, so no server-side refusal can catch it. Whether that can happen depends on the authorization server's supportedresponse_mode, which part (4) covers, and on origin separation.Test plan
docs/packages/cli.mdx,presentandplay)Fails without the fix:
packages/cli/src/commands/oauthReturn.browser.test.ts("an OAuth return that lands on the server's port › cannot be read from the play page" / "… present page") serves the real play and present apps plus a cross-origin redirector in Chrome. On main, all four probes (iframe, iframe via redirect, popup, popup via redirect) readhttp://127.0.0.1:<port>/oauth/callback?code=SECRET&state=s; with the fix, each isunreadableorsevered. The unit tests "a request the play server has no page for" (play.test.ts) and "a request the present server has no page for" (present.test.ts) assert the exact refusal headers and body for/oauth/callback?code=…,/callback?code=…,/?code=…,/composition/index.html?code=…, unknown paths and a missing composition file: 13 cases fail on main.bunx vitest run --project unitinpackages/cli: 8401 passed, 5 failed. The 5 (lambda/deploy,fileWatcher.atomic,projectLock,publishProjectUnicode,whisper/manager-resolution) do not import play or present, and they fail the same way on this machine with the pre-fix sources (4 to 5 per run; one is flaky). They look macOS-local; CI is the arbiter.bunx vitest run --project chrome src/commands/oauthReturn.browser.test.ts: 2 passedbun run typecheck(cli), oxlint and oxfmt on changed files: clean🤖 Generated with Claude Code