@devries-cameron20 / t3code Mirror · read-only / commits / 5aa81a3171
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 13:15 UTC

fix(auth): accept a typed pairing code regardless of letter case (#22089)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: maria-rcks <maria@kuuro.net>

Victor Vogel committed Oct 29, 2026 at 12:48 UTC 5aa81a31718dcd667c502022a568b9ca39c02b7f
2 files changed +42 -5
apps/server/src/auth/PairingGrantStore.test.ts
+30 -3
@@ -1,6 +1,7 @@
1 import { AuthStandardClientScopes } from "@t3tools/contracts";
2 import * as NodeServices from "@effect/platform-node/NodeServices";
3 import { expect, it } from "@effect/vitest";
4 +import * as Crypto from "effect/Crypto";
5 import * as Duration from "effect/Duration";
6 import * as Effect from "effect/Effect";
7 import * as Layer from "effect/Layer";
@@ -45,11 +46,11 @@ const layerPairingGrantStore = (
46 );
47
48 it.layer(NodeServices.layer)("PairingGrantStore.layer", (it) => {
48 - it.effect("issues one-time bootstrap tokens that can only be consumed once", () =>
49 + it.effect("accepts lowercase one-time tokens exactly once", () =>
50 Effect.gen(function* () {
51 const bootstrapCredentials = yield* PairingGrantStore.PairingGrantStore;
52 const issued = yield* bootstrapCredentials.issueOneTimeToken({ label: "Julius iPhone" });
52 - const first = yield* bootstrapCredentials.consume(issued.credential);
53 + const first = yield* bootstrapCredentials.consume(issued.credential.toLowerCase());
54 const second = yield* Effect.flip(bootstrapCredentials.consume(issued.credential));
55
56 expect(first.method).toBe("one-time-token");
@@ -59,7 +60,16 @@ it.layer(NodeServices.layer)("PairingGrantStore.layer", (it) => {
60 expect(issued.label).toBe("Julius iPhone");
61 expect(second._tag).toBe("UnknownBootstrapCredentialError");
62 expect(second.message).toContain("Unknown bootstrap credential");
62 - }).pipe(Effect.provide(layerPairingGrantStore())),
63 + }).pipe(
64 + Effect.provide(layerPairingGrantStore()),
65 + Effect.provideServiceEffect(
66 + Crypto.Crypto,
67 + Effect.map(Crypto.Crypto, (crypto) => ({
68 + ...crypto,
69 + randomBytes: (size) => Effect.succeed(new Uint8Array(size).fill(8)),
70 + })),
71 + ),
72 + ),
73 );
74
75 it.effect("atomically consumes a one-time token when multiple requests race", () =>
@@ -124,6 +134,23 @@ it.layer(NodeServices.layer)("PairingGrantStore.layer", (it) => {
134 }).pipe(Effect.provide(layerPairingGrantStore())),
135 );
136
137 + it.effect("matches a seeded desktop bootstrap credential exactly", () =>
138 + Effect.gen(function* () {
139 + const bootstrapCredentials = yield* PairingGrantStore.PairingGrantStore;
140 + const exact = yield* bootstrapCredentials.consume("abcdefghjkmn");
141 + const otherCase = yield* Effect.flip(bootstrapCredentials.consume("ABCDEFGHJKMN"));
142 +
143 + expect(exact.method).toBe("desktop-bootstrap");
144 + expect(otherCase._tag).toBe("UnknownBootstrapCredentialError");
145 + }).pipe(
146 + Effect.provide(
147 + layerPairingGrantStore({
148 + desktopBootstrapToken: "abcdefghjkmn",
149 + }),
150 + ),
151 + ),
152 + );
153 +
154 it.effect("reports seeded desktop bootstrap credentials as expired after their ttl", () =>
155 Effect.gen(function* () {
156 const bootstrapCredentials = yield* PairingGrantStore.PairingGrantStore;
apps/server/src/auth/PairingGrantStore.ts
+12 -2
@@ -254,6 +254,11 @@ const PAIRING_TOKEN_LENGTH = 12;
254 const PAIRING_TOKEN_REJECTION_LIMIT =
255 Math.floor(256 / PAIRING_TOKEN_ALPHABET.length) * PAIRING_TOKEN_ALPHABET.length;
256
257 +const PAIRING_TOKEN_PATTERN = new RegExp(
258 + `^[${PAIRING_TOKEN_ALPHABET}]{${PAIRING_TOKEN_LENGTH}}$`,
259 + "i",
260 +);
261 +
262 const make = Effect.gen(function* () {
263 const crypto = yield* Crypto.Crypto;
264 const config = yield* ServerConfig.ServerConfig;
@@ -532,10 +537,15 @@ const make = Effect.gen(function* () {
537 return yield* seededResult.error;
538 }
539
540 + // Only credentials in the issued pairing-code format are case-insensitive.
541 + const pairingCredential = PAIRING_TOKEN_PATTERN.test(credential)
542 + ? credential.toUpperCase()
543 + : credential;
544 +
545 // Check scopes in the UPDATE so rejected requests cannot spend one-time links.
546 const consumed = yield* pairingLinks
547 .consumeAvailable({
538 - credential,
548 + credential: pairingCredential,
549 proofKeyThumbprint: input?.proofKeyThumbprint ?? null,
550 ...(input?.requestedScopes !== undefined
551 ? { requestedScopes: input.requestedScopes }
@@ -560,7 +570,7 @@ const make = Effect.gen(function* () {
570 }
571
572 const matching = yield* pairingLinks
563 - .getByCredential({ credential })
573 + .getByCredential({ credential: pairingCredential })
574 .pipe(Effect.mapError((cause) => new BootstrapCredentialLookupError({ cause })));
575 if (Option.isNone(matching)) {
576 return yield* new UnknownBootstrapCredentialError({});