Public: anyone can read this; the crew can change it.

src/apps/proxy.ts hands the signed grants to their own module, with the same answers #15628

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

The signed grants now live in their own module, src/apps/grants.ts, as a move with no rewrites. src/apps/proxy.ts goes from 2,168 to 2,018 lines (150 shorter; the target was at least 130).

Notes

shipped production is serving it deploy 3fede26

opened this

The signed grants now live in their own module, src/apps/grants.ts, as a move with no rewrites. src/apps/proxy.ts goes from 2,168 to 2,018 lines (150 shorter; the target was at least 130).

What moved, unchanged: GrantWho, signGrant, plainProof, the private mac, Grant, readGrant, verifyGrant, identityKey, IDENTITY_HEADERS, identityHeaders, grantUrl and GRANT_URL_TTL_MS (which only grantUrl used). The only new lines are the module's header comment and its imports. createHmac and loadKey left proxy.ts with them; timingSafeEqual stays because the /__forge/grant handler still uses it.

What stayed in proxy.ts: stripForgeCredentials, as the issue asks, plus grantCookieName and GRANT_COOKIE_TTL_MS. Those last two belong to the cookie the grant door sets, and only proxy.ts uses them.

Importers: every source importer now imports from grants.ts: looks/service.ts, actions/apps.ts, actions/feature_tools.ts, contract/probe.ts, and apps/pull_schedule.ts, timer_service.ts, tty.ts, runtime_sleep.ts and runtime_bringup.ts. proxy.ts re-exports the moved names in one line, because about 30 test files import them from proxy.ts and the tests had to stay unedited.

What to look at:

  • Import cycle: grantUrl needs originFor, which is still in proxy.ts, so grants.ts imports it from there. That is a runtime import cycle. It is safe because neither module calls the other while loading, only when a request comes in. Moving originFor and isHostPort somewhere else would remove the cycle, but that is beyond a move, so I left it.
  • The re-export: once the tests import from grants.ts, a later pull can drop it.

Checks:

  • bun scripts/gate.ts --fix changed nothing, and bun x tsc --noEmit is clean.
  • scripts/fast.ts said the change reaches 3,096 test files, too many to run here. I ran the 69 test files that use the grant functions instead, plus the proxy, grant and identity suites: 622 pass, 34 skipped, 1 fails.
  • The one failure is the real-Chromium capture in test/looks.test.ts. It fails the same way on main without this change, because this sandbox can't run a browser.
  • The suites that need unix sockets or cells were skipped here; the forge's check runs them.

The push hook refused until a commit said how to try the change, so the branch has an empty commit: "Try: open a private app's preview while signed in".

The keep_plan and estimate tools weren't available in this run, so the issue has no plan and no estimate recorded.

To try it: open a private app's preview while signed in. The grant door should let you in, and the app should receive the same x-forge-identity and x-forge-signature headers as before.

🤖 Generated with Claude Code

Closes #15623

commented

The signed grants now live in their own module, src/apps/grants.ts, as a move with no rewrites. src/apps/proxy.ts goes from 2,168 to 2,018 lines (150 shorter; the target was at least 130).

What moved, unchanged: GrantWho, signGrant, plainProof, the private mac, Grant, readGrant, verifyGrant, identityKey, IDENTITY_HEADERS, identityHeaders, grantUrl and GRANT_URL_TTL_MS (which only grantUrl used). The only new lines are the module's header comment and its imports. createHmac and loadKey left proxy.ts with them; timingSafeEqual stays because the /__forge/grant handler still uses it.

What stayed in proxy.ts: stripForgeCredentials, as the issue asks, plus grantCookieName and GRANT_COOKIE_TTL_MS. Those last two belong to the cookie the grant door sets, and only proxy.ts uses them.

Importers: every source importer now imports from grants.ts: looks/service.ts, actions/apps.ts, actions/feature_tools.ts, contract/probe.ts, and apps/pull_schedule.ts, timer_service.ts, tty.ts, runtime_sleep.ts and runtime_bringup.ts. proxy.ts re-exports the moved names in one line, because about 30 test files import them from proxy.ts and the tests had to stay unedited.

What to look at:

  • Import cycle: grantUrl needs originFor, which is still in proxy.ts, so grants.ts imports it from there. That is a runtime import cycle. It is safe because neither module calls the other while loading, only when a request comes in. Moving originFor and isHostPort somewhere else would remove the cycle, but that is beyond a move, so I left it.
  • The re-export: once the tests import from grants.ts, a later pull can drop it.

Checks:

  • bun scripts/gate.ts --fix changed nothing, and bun x tsc --noEmit is clean.
  • scripts/fast.ts said the change reaches 3,096 test files, too many to run here. I ran the 69 test files that use the grant functions instead, plus the proxy, grant and identity suites: 622 pass, 34 skipped, 1 fails.
  • The one failure is the real-Chromium capture in test/looks.test.ts. It fails the same way on main without this change, because this sandbox can't run a browser.
  • The suites that need unix sockets or cells were skipped here; the forge's check runs them.

The push hook refused until a commit said how to try the change, so the branch has an empty commit: "Try: open a private app's preview while signed in".

The keep_plan and estimate tools weren't available in this run, so the issue has no plan and no estimate recorded.

To try it: open a private app's preview while signed in. The grant door should let you in, and the app should receive the same x-forge-identity and x-forge-signature headers as before.

🤖 Generated with Claude Code

commented

The signed grants now live in their own module, src/apps/grants.ts, as a move with no rewrites. src/apps/proxy.ts goes from 2,168 to 2,018 lines (150 shorter; the target was at least 130).

What moved, unchanged: GrantWho, signGrant, plainProof, the private mac, Grant, readGrant, verifyGrant, identityKey, IDENTITY_HEADERS, identityHeaders, grantUrl and GRANT_URL_TTL_MS (which only grantUrl used). The only new lines are the module's header comment and its imports. createHmac and loadKey left proxy.ts with them; timingSafeEqual stays because the /__forge/grant handler still uses it.

What stayed in proxy.ts: stripForgeCredentials, as the issue asks, plus grantCookieName and GRANT_COOKIE_TTL_MS. Those last two belong to the cookie the grant door sets, and only proxy.ts uses them.

Importers: every source importer now imports from grants.ts: looks/service.ts, actions/apps.ts, actions/feature_tools.ts, contract/probe.ts, and apps/pull_schedule.ts, timer_service.ts, tty.ts, runtime_sleep.ts and runtime_bringup.ts. proxy.ts re-exports the moved names in one line, because about 30 test files import them from proxy.ts and the tests had to stay unedited.

What to look at:

  • Import cycle: grantUrl needs originFor, which is still in proxy.ts, so grants.ts imports it from there. That is a runtime import cycle. It is safe because neither module calls the other while loading, only when a request comes in. Moving originFor and isHostPort somewhere else would remove the cycle, but that is beyond a move, so I left it.
  • The re-export: once the tests import from grants.ts, a later pull can drop it.
  • Gate reasons: two empty commits give the gate the reasons it asks for: "No test" (no behaviour changes, and the existing grant, proxy and identity tests pass unedited), "No door" (an internal module, not a feature) and "Direction" (named as going ahead of #6534). The first push was refused until a commit said how to try the change, so there is also an empty "Try:" commit.
  • Similarity note: the gate notes that verifyGrant looks like readClaim in src/spawn/claim.ts. That is a note, not a failure, and merging them would be a rewrite, so I left it.

Checks:

  • bun scripts/gate.ts now exits 0 with no failing rules, and bun x tsc --noEmit is clean.
  • I ran the 69 test files that use the grant functions, plus the proxy, grant and identity suites: 622 pass, 34 skipped, 1 fails. That run was before the gate commits, which change no files.
  • The one failure is the real-Chromium capture in test/looks.test.ts. It fails the same way on main without this change, because the sandbox can't run a browser.
  • The suites that need unix sockets or cells were skipped here; the forge's check runs them.

The keep_plan and estimate tools weren't available in this run, so the issue has no plan and no estimate recorded.

To try it: open a private app's preview while signed in. The grant door should let you in, and the app should receive the same x-forge-identity and x-forge-signature headers as before.

🤖 Generated with Claude Code

Approved

A faithful move: the grant code is byte-for-byte what it was, every source importer now points at grants.ts, proxy.ts is about 150 lines shorter, and no test was edited. No security surface changes: the HMAC and timingSafeEqual checks and the identity headers are unchanged. Two things I would do next: (1) break the proxy.ts <-> grants.ts import cycle by moving originFor (and isHostPort) into its own module, so grants.ts no longer imports from proxy.ts; (2) repoint the ~30 test imports at grants.ts in one mechanical pull and delete the re-export shim in proxy.ts. The empty marker commits are noise but harmless.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs