Skip to content

fix(cli): preview answers unknown paths with an inert refusal, not the Studio shell (SECOPS-2642 part 1) - #8161

Draft
Vitozhu04 wants to merge 1 commit into
mainfrom
claude/secops-2642-preview-catchall-a574f4
Draft

Vitozhu04 wants to merge 1 commit into
mainfrom
claude/secops-2642-preview-catchall-a574f4

Conversation

@Vitozhu04

Copy link
Copy Markdown
Collaborator

What

SECOPS-2642 part 1. hyperframes preview 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.

Studio routes by location.hash only, so it never needs a path:

  • The shell is served only at / and /index.html. /assets/*, /icons/*, /favicon.svg, /api/* and /__hyperframes_config are unchanged.
  • Any other path, for any method, gets a plain-text 404 Not found..
  • A request carrying code or state at any path gets a plain-text 400. That includes / and /api/projects/:id/preview, which loads project script. This runs as the first middleware. No Studio route uses either parameter.
  • Both refusals send a fixed body and never echo the request. Their headers: Content-Type: text/plain, X-Content-Type-Options: nosniff, Content-Security-Policy: sandbox; 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 CSP sandbox gives the page an opaque origin, so a same-origin opener or parent cannot read its address. COOP alone leaves a same-origin popup readable. This is the same header set as the part 3 refusal in fix(cli): play and present answer unknown paths with an inert refusal (SECOPS-2642 part 3) #8160, but a separate copy here.

The CLI's own login (packages/cli/src/auth/loopback.ts) runs its own node:http server on an ephemeral port and is untouched. src/auth tests pass.

Tests

New packages/cli/src/server/studioServer.unknownPaths.test.ts:

  • /oauth/callback and /callback with code and state, on 127.0.0.1 and localhost, plus four unknown paths. Each must be non-HTML with the headers above and must not contain the code, the state, < or the shell.
  • code and/or state on /, /index.html and /api/projects/project/preview, and on a POST.
  • The entry routes /, /index.html and /?hf_canary_… still serve the shell.

Fails without the fix: studioServer.unknownPaths.test.ts. 13 of 16 tests fail against main's studioServer.ts. For example, "refuses an OAuth return at /oauth/callback instead of serving the Studio shell" gets expected 200 to be greater than or equal to 400, and the preview-route and POST cases get expected null to be 'nosniff'. The 3 entry-route tests pass on both.

Two existing tests assumed the shell at a made-up SPA path (/editor, /projects/demo). They now hit /index.html.

Other parts of SECOPS-2642 (not in this PR)

Verification

  • vitest run for src/server + src/auth: all pass, apart from the known-flaky fileWatcher.atomic real-FS test, which passes on rerun.
  • Full cli suite: 7 failures. All of them also fail against main's studioServer.ts on this machine (openWritesNothing is 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 and comment-ratchet are clean.
  • Not verified: a real browser run of the OAuth redirect against a live hyperframes preview. The tests check the server responses and headers, not browser COOP/sandbox behaviour.

🤖 Generated with Claude Code

…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
(SECOPS-2642, part 1).

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

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 253 (base branch 253), smooth 71 of those

The gate fails: 14 of 15 shards reported results.
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)

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

This branch has not been deployed

No deployments
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.

1 participant