fix(server): make the desktop-bootstrap grant reusable for 24h
The desktop-bootstrap credential used the same single-use + 5-minute TTL semantics as a user-facing pairing link. That fit the original mental model (one renderer, one bootstrap exchange) but breaks parallel backends where a slow WSL cold boot lands outside the renderer's first reconcile pass, and breaks page reloads where the renderer no longer has the bearer it traded the bootstrap for and needs to re-exchange. Switch the seed for `desktopBootstrapToken` to `remainingUses: "unbounded"` with a 24h TTL. The seed is delivered over trusted IPC (fd3 / stdin) at backend launch and lives in the renderer/desktop processes the user already trusts, so single-use buys us nothing operationally and costs us recoverable error paths. Tests: - BootstrapCredentialService.test.ts now asserts repeat consumption succeeds and that expiry kicks in past 24h, not 5 minutes. - server.test.ts: the "rejects reusing" test is rewritten as "allows reusing" against the same credential.
This commit is contained in:
1 parent
df236913e5
commit
2c1620db00
4 files changed
+38
-17
No files matched your search
@@ -87,17 +87,18 @@ it.layer(NodeServices.layer)("BootstrapCredentialServiceLive", (it) => {
|
||||
}).pipe(Effect.provide(makeBootstrapCredentialLayer())),
|
||||
);
|
||||
|
||||
it.effect("seeds the desktop bootstrap credential as a one-time grant", () =>
|
||||
it.effect("seeds the desktop bootstrap credential as a reusable grant", () =>
|
||||
Effect.gen(function* () {
|
||||
const bootstrapCredentials = yield* BootstrapCredentialService;
|
||||
const first = yield* bootstrapCredentials.consume("desktop-bootstrap-token");
|
||||
const second = yield* Effect.flip(bootstrapCredentials.consume("desktop-bootstrap-token"));
|
||||
const second = yield* bootstrapCredentials.consume("desktop-bootstrap-token");
|
||||
const third = yield* bootstrapCredentials.consume("desktop-bootstrap-token");
|
||||
|
||||
expect(first.method).toBe("desktop-bootstrap");
|
||||
expect(first.role).toBe("owner");
|
||||
expect(first.subject).toBe("desktop-bootstrap");
|
||||
expect(second._tag).toBe("BootstrapCredentialError");
|
||||
expect(second.status).toBe(401);
|
||||
expect(second.method).toBe("desktop-bootstrap");
|
||||
expect(third.method).toBe("desktop-bootstrap");
|
||||
}).pipe(
|
||||
Effect.provide(
|
||||
makeBootstrapCredentialLayer({
|
||||
@@ -111,7 +112,13 @@ it.layer(NodeServices.layer)("BootstrapCredentialServiceLive", (it) => {
|
||||
Effect.gen(function* () {
|
||||
const bootstrapCredentials = yield* BootstrapCredentialService;
|
||||
|
||||
yield* TestClock.adjust(Duration.minutes(6));
|
||||
// The desktop-bootstrap grant lives for 24h. Within that window
|
||||
// it stays reusable.
|
||||
yield* TestClock.adjust(Duration.hours(12));
|
||||
const stillValid = yield* bootstrapCredentials.consume("desktop-bootstrap-token");
|
||||
expect(stillValid.method).toBe("desktop-bootstrap");
|
||||
|
||||
yield* TestClock.adjust(Duration.hours(13));
|
||||
const expired = yield* Effect.flip(bootstrapCredentials.consume("desktop-bootstrap-token"));
|
||||
|
||||
expect(expired._tag).toBe("BootstrapCredentialError");
|
||||
|
||||
@@ -36,6 +36,15 @@ type ConsumeResult =
|
||||
};
|
||||
|
||||
const DEFAULT_ONE_TIME_TOKEN_TTL_MINUTES = Duration.minutes(5);
|
||||
// The desktop-bootstrap grant rides on a trusted IPC channel (fd3 or
|
||||
// stdin) at backend launch, so it doesn't have to be short-lived the
|
||||
// way a user-facing pairing link does. Letting it live for the
|
||||
// lifetime of the backend process (24h is more than long enough for
|
||||
// practical desktop use, and well under "forever" in case the seed
|
||||
// gets logged anywhere by accident) means a page reload past the 5-min
|
||||
// window can still recover by re-bootstrapping rather than locking
|
||||
// the user out of the backend.
|
||||
const DESKTOP_BOOTSTRAP_TTL_HOURS = Duration.hours(24);
|
||||
const PAIRING_TOKEN_ALPHABET = "23456789ABCDEFGHJKLMNPQRSTUVWXYZ";
|
||||
const PAIRING_TOKEN_LENGTH = 12;
|
||||
|
||||
@@ -90,9 +99,14 @@ export const makeBootstrapCredentialService = Effect.gen(function* () {
|
||||
role: "owner",
|
||||
subject: "desktop-bootstrap",
|
||||
expiresAt: DateTime.add(now, {
|
||||
milliseconds: Duration.toMillis(DEFAULT_ONE_TIME_TOKEN_TTL_MINUTES),
|
||||
milliseconds: Duration.toMillis(DESKTOP_BOOTSTRAP_TTL_HOURS),
|
||||
}),
|
||||
remainingUses: 1,
|
||||
// Unbounded uses so the renderer can re-exchange the seed for a
|
||||
// fresh bearer session after a page reload (or after the prior
|
||||
// bearer expires). The seed itself stays inside the desktop
|
||||
// process and the rendered page, both of which the user already
|
||||
// implicitly trusts.
|
||||
remainingUses: "unbounded",
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1577,19 +1577,19 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
|
||||
}).pipe(Effect.provide(NodeHttpServer.layerTest)),
|
||||
);
|
||||
|
||||
it.effect("rejects reusing the same bootstrap credential after it has been exchanged", () =>
|
||||
it.effect("allows reusing the desktop bootstrap credential", () =>
|
||||
Effect.gen(function* () {
|
||||
// The desktop-bootstrap grant is delivered over trusted IPC at
|
||||
// backend launch and needs to stay claimable after a renderer
|
||||
// refresh, so it's intentionally reusable (unlike user-facing
|
||||
// one-time pairing credentials).
|
||||
yield* buildAppUnderTest();
|
||||
|
||||
const first = yield* bootstrapBrowserSession();
|
||||
const second = yield* bootstrapBrowserSession();
|
||||
|
||||
assert.equal(first.response.status, 200);
|
||||
assert.equal(second.response.status, 401);
|
||||
assert.equal(
|
||||
(second.body as { readonly error?: string }).error,
|
||||
"Invalid bootstrap credential.",
|
||||
);
|
||||
assert.equal(second.response.status, 200);
|
||||
}).pipe(Effect.provide(NodeHttpServer.layerTest)),
|
||||
);
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
},
|
||||
"apps/desktop": {
|
||||
"name": "@t3tools/desktop",
|
||||
"version": "0.0.23",
|
||||
"version": "0.0.24",
|
||||
"dependencies": {
|
||||
"@effect/platform-node": "catalog:",
|
||||
"@t3tools/contracts": "workspace:*",
|
||||
@@ -50,7 +50,7 @@
|
||||
},
|
||||
"apps/server": {
|
||||
"name": "t3",
|
||||
"version": "0.0.23",
|
||||
"version": "0.0.24",
|
||||
"bin": {
|
||||
"t3": "./dist/bin.mjs",
|
||||
},
|
||||
@@ -83,7 +83,7 @@
|
||||
},
|
||||
"apps/web": {
|
||||
"name": "@t3tools/web",
|
||||
"version": "0.0.23",
|
||||
"version": "0.0.24",
|
||||
"dependencies": {
|
||||
"@base-ui/react": "^1.4.1",
|
||||
"@dnd-kit/core": "^6.3.1",
|
||||
@@ -165,7 +165,7 @@
|
||||
},
|
||||
"packages/contracts": {
|
||||
"name": "@t3tools/contracts",
|
||||
"version": "0.0.23",
|
||||
"version": "0.0.24",
|
||||
"dependencies": {
|
||||
"effect": "catalog:",
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user