Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions apps/server/src/auth/PairingGrantStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,22 @@ it.layer(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))("PairingGrantStor
),
);

it.effect("accepts a one-time token typed in hyphen- or space-separated groups", () =>
Effect.gen(function* () {
const bootstrapCredentials = yield* PairingGrantStore.PairingGrantStore;
const issued = yield* bootstrapCredentials.issueOneTimeToken();
const formatted = issued.credential.match(/.{1,4}/g)!.join("-");
const consumed = yield* bootstrapCredentials.consume(formatted.toLowerCase());
const second = yield* bootstrapCredentials.issueOneTimeToken();
const spaced = yield* bootstrapCredentials.consume(
second.credential.match(/.{1,4}/g)!.join(" "),
);

expect(consumed.method).toBe("one-time-token");
expect(spaced.method).toBe("one-time-token");
}).pipe(Effect.provide(layerPairingGrantStore())),
);

it.effect("atomically consumes a one-time token when multiple requests race", () =>
Effect.gen(function* () {
const bootstrapCredentials = yield* PairingGrantStore.PairingGrantStore;
Expand Down
6 changes: 4 additions & 2 deletions apps/server/src/auth/PairingGrantStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -561,8 +561,10 @@ const make = Effect.gen(function* () {
}

// Only credentials in the issued pairing-code formats are case-insensitive.
const pairingCredential = PAIRING_TOKEN_PATTERN.test(credential)
? credential.toUpperCase()
// People type codes in groups such as XXXX-XXXX-XXXX.
const compactCredential = credential.replace(/[\s-]/g, "");
const pairingCredential = PAIRING_TOKEN_PATTERN.test(compactCredential)
? compactCredential.toUpperCase()
: (parseMcpApprovalCode(credential)?.code ?? credential);

// Check scopes in the UPDATE so rejected requests cannot spend one-time links.
Expand Down
Loading