Skip to content

fix(cli): play and present answer unknown paths with an inert refusal - #8160

Merged
Vitozhu04 merged 2 commits into
mainfrom
claude/secops-2642-play-present-feb2a4
Nov 18, 2026
Merged

Vitozhu04 merged 2 commits into
mainfrom
claude/secops-2642-play-present-feb2a4

Conversation

@Vitozhu04

@Vitozhu04 Vitozhu04 commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

What

hyperframes play and hyperframes present now answer two kinds of request with a fixed plain-text Not found (status 404) that no script can read:

  • any path they have no page for (including a missing /composition/* file), and
  • any request whose query carries code or state, on any path, / included.

The response is text/plain with nosniff, never echoes the request, and carries Cross-Origin-Opener-Policy: same-origin, a CSP of sandbox; default-src 'none'; frame-ancestors 'none', X-Frame-Options: DENY, Referrer-Policy: no-referrer and Cache-Control: no-store. The CSP sandbox puts 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 of run() into an exported buildPlayApp, like present's buildPresentApp, so tests can serve the real app.

Why

HeyGen's sign-in returns a CLI code to any loopback port. play and present serve 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=… through parent, 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 sandbox closes that case, and a top-level visit still shows an ordinary 404.

Scope and follow-ups

  • Separate PRs: (1) Studio preview's catch-all in studioServer.ts, and (4) backend loopback consent in experiment-framework. This PR does not touch studioServer.ts.
  • Helper kept local: the refusal helper is 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.
  • Follow-up, origin separation: project script in play/present should also not share an origin with a page that can observe navigations to the server. It still does after this PR, because the player page and composition share one origin. This PR removes the readable landing document, but it does not separate the origins. To separate them, play/present would have to drop 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.
  • Residual: a return delivered in the URL fragment (/#code=…) never reaches the server, so no server-side refusal can catch it. Whether that can happen depends on the authorization server's supported response_mode, which part (4) covers, and on origin separation.

Test plan

  • Unit tests added/updated
  • Manual testing performed (header candidates probed in system Chrome; see Why)
  • Documentation updated (docs/packages/cli.mdx, present and play)
  • Comments follow CONTRIBUTING.md "Comments"

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) read http://127.0.0.1:<port>/oauth/callback?code=SECRET&state=s; with the fix, each is unreadable or severed. 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 unit in packages/cli: 8401 passed, 5 failed. The 5 (lambda/deploy, fileWatcher.atomic, projectLock, publishProject Unicode, 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 passed
  • bun run typecheck (cli), oxlint and oxfmt on changed files: clean

🤖 Generated with Claude Code

@mintlify

mintlify Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

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

Project Status Preview Updated
hyperframes 🟢 Ready View Preview Nov 18, 2026, 11:34 AM

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

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Edit accuracy did not run: 0 of 15 shards reported results; see the shard jobs.

Nothing was compared with the base branch.

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

Vitozhu04 and others added 2 commits November 18, 2026 19:30
… (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>

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

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 refuseUnknownHosts in 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 encoded code key, 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 no Cross-Origin-Resource-Policy. #8161's inertRefusal.ts answers 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:191 in 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.

@Vitozhu04
Vitozhu04 marked this pull request as ready for review November 18, 2026 14:55
@Vitozhu04
Vitozhu04 added this pull request to the merge queue Nov 18, 2026
Merged via the queue into main with commit fc289b0 Nov 18, 2026
85 checks passed
@Vitozhu04
Vitozhu04 deleted the claude/secops-2642-play-present-feb2a4 branch November 18, 2026 15:15
@Vitozhu04 Vitozhu04 changed the title fix(cli): play and present answer unknown paths with an inert refusal (SECOPS-2642 part 3) fix(cli): play and present answer unknown paths with an inert refusal Nov 20, 2026

This branch was successfully deployed

1 active deployment
staging - docs — de900d59 Deployed Nov 18, 2026 by mintlify[bot]
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.

4 participants