Add reusable loopback development auth - #4360
Conversation
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 6ddeaf0. Configure here.
ApprovabilityVerdict: Needs human review This PR modifies authentication logic in You can customize Macroscope's approvability policy. Learn more. |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
apps/server/src/auth/PairingGrantStore.test.ts (1)
201-221: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAssert the reusable grant’s full shape on the second consume.
The test checks only
second.subject; a regression could return the wrong method or reduced scopes after reuse while still passing.Suggested assertions
expect(second.subject).toBe("development-bootstrap"); + expect(second.method).toBe("desktop-bootstrap"); + expect(second.scopes).toEqual(first.scopes);🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/server/src/auth/PairingGrantStore.test.ts` around lines 201 - 221, Expand the assertions for the second consume in the “seeds the development credential” test to verify its full grant shape, including method, subject, and complete scopes. Match the existing first-grant expectations so reuse is confirmed to preserve all grant fields.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/shared/src/networkHost.ts`:
- Around line 1-13: Update packages/shared/src/networkHost.ts at lines 1-13 so
isLoopbackHost accepts only validated loopback address literals, returning false
for omitted hosts and rejecting hostname-like values such as
127.attacker.example; update apps/server/src/cli/config.ts at lines 362-368 to
require an explicit validated loopback bind before enabling dev auth; update
scripts/dev-runner.ts at lines 326-334 to provision dev auth only with an
explicit 127.0.0.1 bind, otherwise leave it disabled; add regression coverage
for an omitted host and 127.attacker.example.
---
Nitpick comments:
In `@apps/server/src/auth/PairingGrantStore.test.ts`:
- Around line 201-221: Expand the assertions for the second consume in the
“seeds the development credential” test to verify its full grant shape,
including method, subject, and complete scopes. Match the existing first-grant
expectations so reuse is confirmed to preserve all grant fields.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: e6601f36-61f6-4463-aa10-624815e2af0c
📒 Files selected for processing (21)
.agents/skills/test-t3-app/SKILL.md.agents/skills/test-t3-mobile/SKILL.md.plans/21-agent-dev-auth.htmlapps/mobile/src/features/connection/ConnectionsNewRouteScreen.tsxapps/server/src/auth/EnvironmentAuthPolicy.test.tsapps/server/src/auth/EnvironmentAuthPolicy.tsapps/server/src/auth/PairingGrantStore.test.tsapps/server/src/auth/PairingGrantStore.tsapps/server/src/auth/SessionStore.tsapps/server/src/auth/utils.tsapps/server/src/bin.test.tsapps/server/src/cli/config.test.tsapps/server/src/cli/config.tsapps/server/src/config.tsapps/server/src/environment/ServerEnvironment.test.tsapps/server/src/server.test.tsapps/server/src/startupAccess.tspackages/shared/package.jsonpackages/shared/src/networkHost.tsscripts/dev-runner.test.tsscripts/dev-runner.ts

Summary
The development key intentionally assumes a single-user development machine. It is not a production secret, and server config rejects it on wildcard, LAN, Tailnet, or other non-loopback binds. Real pairing remains unchanged.
Verification
vp test run scripts/dev-runner.test.ts apps/server/src/cli/config.test.ts apps/server/src/auth/PairingGrantStore.test.ts apps/server/src/auth/EnvironmentAuthPolicy.test.ts apps/server/src/startupAccess.test.ts apps/mobile/src/features/connection/pairing.test.ts(66 tests)git diff --checkNote
Add reusable loopback development auth for simulators and emulators
T3CODE_DEV_AUTH=1and a stableT3CODE_DEV_AUTH_KEY(SHA-256 of the worktree root) are injected by the dev runner when binding to the loopback host, enabling reusable pairing without one-time tokens.desktop-bootstrapgrant underdevAuthKeyat startup with unbounded uses and a far-future expiration, so simulators/emulators can reconnect via a stable deep link.isLoopbackAddress,isLoopbackHost,isWildcardHost, andformatHostForUrlutilities to@t3tools/shared/networkHost, and migratesstartupAccess.tsto use them; renames the preview-scopedisLoopbackHosttoisPreviewLocalHostto avoid collision.devAuthKeyis configured, isolating dev sessions by port.Macroscope summarized 7c9a298.
Note
High Risk
Introduces a reusable administrative bootstrap grant and dev-only auth wiring; risk is mitigated by explicit env flags, loopback-only binding checks, and Tailscale Serve rejection, but misconfiguration could still widen local privilege.
Overview
Adds worktree-scoped reusable dev authentication so agents and local tooling can pair web and simulators without burning one-time tokens.
The dev runner derives a stable key from the canonical worktree path (
sha256("t3-dev:" + root)), setsT3CODE_DEV_AUTH/T3CODE_DEV_AUTH_KEYonly fordev/dev:serverbound to127.0.0.1, and logs reusable web, iOS, and Android pairing URLs. Non-127.0.0.1hosts skip dev auth (physical LAN still uses real pairing).The server reads
devAuthKeyfrom config, seeds an unlimited administrative bootstrap grant inPairingGrantStore(same exchange path as desktop bootstrap), and suffixes session cookies by port when dev auth is on so parallel backends do not clobber cookies. Startup rejects dev auth without a key, on non-loopback binds, or with Tailscale Serve.Mobile
connections/newaccepts apairingUrlparam and auto-runs the existing connect flow once per URL. Agent skills and a new implementation plan document describe reusable URLs vs one-time recovery.Shared adds
@t3tools/shared/networkHostwith a strictisLoopbackAddressfor dev-auth policy; preview code renames loopback checks toisPreviewLocalHostso preview behavior stays separate.Reviewed by Cursor Bugbot for commit 7c9a298. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary by CodeRabbit
New Features
Bug Fixes
Documentation