fix(auth): address Copilot review round 13

No new inline comments this round, but two of the four suppressed ones were
real defects rather than restatements — both in code I added, both silently
wrong in the safe-looking direction.

**A symlinked secrets directory read as unmounted.** `isOnMountPoint` walks
to the nearest existing ancestor *lexically* and then string-prefixes it
against mountinfo, so `~/.mcp-inspector -> /data/inspector` with `/data`
mounted matched no mount point. The container then selected the session-only
store on a box that had explicitly arranged for persistence, and nothing said
so — the mount was there, the volume was there, the secrets evaporated on
exit. Resolved through symlinks now, tolerantly: a path that cannot be
resolved falls back to the lexical comparison, which is what this did before
and is correct whenever no symlink is involved. The `statSync` fallback branch
already followed links, so this also makes the two paths agree.

**The bulk read did not fix the case it was written for.** `getMany` batched
*one server's* fields, but both rehydration callers iterate servers — so a
catalog of 20 servers holding one secret each still paid 20 serialized scrypt
derivations. The same ~450ms stall the seam was introduced to remove, reached
one server at a time instead of one field at a time. Measuring the wrong unit
and then optimizing it is worse than not optimizing, because the number in the
commit message says it is fixed.

The seam is cross-server now — `getMany(requests: SecretBulkRequest[])` — and
both callers pass the whole catalog in one call. `FileSecretStore` decrypts
once for the entire rehydration; the keychain fallback still issues
independent parallel `get`s, which is what it wants. A test asserts one
derivation for four servers, next to the existing one asserting one for three
fields, so the property is pinned at both axes.

The other two suppressed comments are the cross-process guarantee — `mutate`'s
residual and the hand-off's TOCTOU delete — which remain decided against for
this PR and tracked in #2082.

Full `npm run ci` green.

Signed-off-by: cliffhall <cliff@futurescale.com>
This commit is contained in:
cliffhall 2026-08-22 19:39:45 -04:00
commit 26d2f58784

View file

@ -64,6 +64,7 @@ import * as path from "node:path";
import { readStoreFile, writeStoreFile } from "../../storage/store-io.js";
import {
SecretStoreUnavailableError,
type SecretBulkRequest,
type SecretStore,
} from "./secret-store.js";
@ -683,29 +684,32 @@ export class FileSecretStore implements SecretStore {
}
/**
* One read and one derivation for a whole server's fields.
* One read and one derivation for an entire rehydration.
*
* The reason this exists: `get` reads and decrypts the entire file, and
* the rehydration callers ask field by field — so an encrypted catalog
* paid N scrypt derivations per server, serialized behind this store's own
* queue, every time the server list was loaded. Tolerant like `get`: an
* unreadable store yields no fields rather than throwing.
* `get` reads and decrypts the whole file, so the cost is per *call*, not
* per field — which is why the batch has to span servers. A per-server
* version of this shipped first and left a 20-server catalog paying 20
* serialized derivations, the same stall it was written to remove.
* Tolerant like `get`: an unreadable store yields no fields for anyone
* rather than throwing.
*/
async getMany(
serverId: string,
fields: string[],
): Promise<Record<string, string>> {
requests: SecretBulkRequest[],
): Promise<Record<string, Record<string, string>>> {
let map: Record<string, string> | null;
try {
map = await this.serialize(() => this.readMap());
} catch {
return {};
map = null;
}
if (!map) return {};
const out: Record<string, string> = {};
for (const field of fields) {
const value = map[buildAccount(serverId, field)];
if (value !== undefined) out[field] = value;
const out: Record<string, Record<string, string>> = {};
for (const { serverId, fields } of requests) {
const found: Record<string, string> = {};
for (const field of fields) {
const value = map?.[buildAccount(serverId, field)];
if (value !== undefined) found[field] = value;
}
out[serverId] = found;
}
return out;
}