Stabilize auth session cookies per server mode#1898
Stabilize auth session cookies per server mode#1898juliusmarminge wants to merge 4 commits intomainfrom
Conversation
- Use port-scoped cookies for desktop mode - Log rejected session credentials with reasons - Update auth policy and server tests
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
ApprovabilityVerdict: Needs human review This PR modifies authentication session cookie naming in the You can customize Macroscope's approvability policy. Learn more. |
- Log `SessionCredentialError.message` directly when session auth fails - Remove redundant auth failure reason helper
- probe required wildcard hosts before reusing a port - move desktop/dev defaults to the higher port range - add coverage for host-specific port availability
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix prepared fixes for both issues found in the latest run.
- ✅ Fixed: Concurrent port probes on overlapping hosts cause self-interference
- Replaced Promise.all concurrent host probes with a sequential for-of loop that short-circuits on the first unavailable host, preventing EADDRINUSE self-interference between overlapping addresses binding to the same port.
- ✅ Fixed: Test no longer exercises non-required port overflow edge case
- Changed the test to use offset 51763 with requireServerPort=false and requireWebPort=true so that the server port (65536) exceeds MAX_PORT while the web port (57496) stays in range, correctly exercising the non-required port overflow edge case.
Or push these changes by commenting:
@cursor push ef7768e7e2
Preview (ef7768e7e2)
diff --git a/apps/desktop/src/backendPort.ts b/apps/desktop/src/backendPort.ts
--- a/apps/desktop/src/backendPort.ts
+++ b/apps/desktop/src/backendPort.ts
@@ -58,10 +58,14 @@
// Keep desktop startup predictable across app restarts by probing upward from
// the same preferred port instead of picking a fresh ephemeral port.
for (let port = startPort; port <= maxPort; port += 1) {
- const availability = await Promise.all(
- hostsToCheck.map((candidateHost) => canListenOnHost(port, candidateHost)),
- );
- if (availability.every(Boolean)) {
+ let allAvailable = true;
+ for (const candidateHost of hostsToCheck) {
+ if (!(await canListenOnHost(port, candidateHost))) {
+ allAvailable = false;
+ break;
+ }
+ }
+ if (allAvailable) {
return port;
}
}
diff --git a/scripts/dev-runner.test.ts b/scripts/dev-runner.test.ts
--- a/scripts/dev-runner.test.ts
+++ b/scripts/dev-runner.test.ts
@@ -246,13 +246,13 @@
it.effect("allows offsets where only non-required ports exceed max", () =>
Effect.gen(function* () {
const offset = yield* findFirstAvailableOffset({
- startOffset: 51_762,
- requireServerPort: true,
- requireWebPort: false,
+ startOffset: 51_763,
+ requireServerPort: false,
+ requireWebPort: true,
checkPortAvailability: () => Effect.succeed(true),
});
- assert.equal(offset, 51_762);
+ assert.equal(offset, 51_763);
}),
);
});You can send follow-ups to the cloud agent here.
Reviewed by Cursor Bugbot for commit 1213650. Configure here.
- Probe candidate hosts sequentially for desktop and dev runner ports - Update tests for the new availability check behavior and error text


Summary
Testing
Note
Medium Risk
Changes session cookie naming for desktop mode (now
t3_session_<port>), which will invalidate existing desktop cookie sessions and could affect authentication flows if any consumers assume a fixed cookie name. Port selection logic now requires availability across multiple hosts, which may change which ports are chosen on some systems.Overview
Desktop auth sessions are now port-scoped:
resolveSessionCookieNamereturnst3_sessionfor web mode butt3_session_<port>for desktop mode, and bothServerAuthPolicyandSessionCredentialServicenow derive the cookie name fromServerConfig.Desktop backend/dev port selection is tightened to only accept a port if it can bind on all required hosts (e.g. loopback + wildcard/IPv6), with sequential host checks to avoid self-interference; tests are updated accordingly. The dev runner’s default server port base shifts from
3773to13773, and server/desktop tests are adjusted to match the new cookie/port expectations.Reviewed by Cursor Bugbot for commit d8c3a5a. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Stabilize auth session cookies and port selection per server mode
resolveSessionCookieNamein auth/utils.ts:t3_sessionfor web mode andt3_session_<port>for desktop mode, preventing cookie collisions across desktop instances.3773to13773in dev-runner.ts.SESSION_COOKIE_NAMEconstant must now useresolveSessionCookieName; the default dev port shifts from3773to13773.Macroscope summarized d8c3a5a.