fix(auth): address Copilot review on the secret-store PR
Six findings, all taken.
- The descriptor reported the *write policy*, not the file. Adding
`MCP_INSPECTOR_SECRET_KEY` to an install that already has a plaintext
file flipped `store.encrypted` immediately, so the banner and footer
claimed "File (encrypted)" while the existing secrets sat readable
until the next `set`. `FileSecretStore.readOnDiskEncryption()` now
reads the envelope (never the payload, so it needs no passphrase) and
the descriptor is built from that. The transitional state gets its own
`pendingEncryption` flag, which changes the advice without softening
the verdict — "set a passphrase" is the wrong thing to tell someone who
already has, so the caveat names the pending write instead.
- The secrets file ignored the configured storage directory. A container
mounting only that directory was judged unmounted, fell back to
`memory`, and lost secrets the user had arranged to keep.
`defaultSecretFilePath()` now follows `MCP_STORAGE_DIR` — the variable
that already relocates OAuth tokens and `client.json` — between the
explicit `MCP_INSPECTOR_SECRET_FILE` and the `~/.mcp-inspector`
default. (The issue comment called it `MCP_INSPECTOR_STORAGE_DIR`; no
such variable exists.)
- `version` was never checked before the plaintext branch, so a
`{ version: 2, encryption: "none" }` file was read and silently
rewritten as version 1, discarding whatever the newer format added —
the same destroy-to-satisfy-an-additive-request case the encrypted
branch already refuses. Checked first now, so the answer no longer
depends on which encryption mode the newer writer chose.
- The doc comment claimed a per-file salt made "a short, memorable value
safe to use". It does not: the salt defeats precomputation, not
guessing, and the scrypt cost is deliberately a few milliseconds
because it runs on every read and write. Both the comment and the
README now say to use a high-entropy value, generated rather than
chosen.
- `usableSecretStorage` validated only `kind`, so a partial
`{ kind: "file" }` was cast through and — because a missing `plaintext`
is falsy — rendered as the quiet, neutral *encrypted* file. That is the
confident half-answer the guard exists to reject, produced by the
absence of information rather than by any claim the backend made.
`reason`, `durable`, and each kind's own required fields are checked.
- The footer's inline `Tooltip` carried four static props; extracted to a
`CaveatTooltip` constant per the `.withProps()` rule.
Tests cover each: the policy/file disagreement in both directions and the
no-file-yet fallback, `MCP_STORAGE_DIR` and its precedence against
`MCP_INSPECTOR_SECRET_FILE`, the version refusal (asserting the bytes
survive it) split from the unrecognized-cipher refusal it used to be
conflated with, `readOnDiskEncryption` including the keyless and
unparseable cases, five new rejected descriptor shapes, and the changed
caveat. Full `npm run ci` green.
Signed-off-by: cliffhall <cliff@futurescale.com>
This commit is contained in:
parent
bc408f5869
commit
3452a63101
2 changed files with 411 additions and 75 deletions
|
|
@ -87,6 +87,22 @@ describe("secretStorageCaveat", () => {
|
|||
expect(caveat).toContain("MCP_INSPECTOR_SECRET_KEY");
|
||||
});
|
||||
|
||||
it("changes the advice once a passphrase is set but not yet applied", () => {
|
||||
// Telling someone to set MCP_INSPECTOR_SECRET_KEY when they already have
|
||||
// is advice that cannot clear the condition. The condition here is the
|
||||
// pending write, so that is what the sentence names — while the verdict
|
||||
// (still unencrypted, still a warning) stays exactly the same.
|
||||
const pending: SecretStorageInfo = {
|
||||
...plaintextFile,
|
||||
pendingEncryption: true,
|
||||
};
|
||||
expect(secretStorageTone(pending)).toBe("warn");
|
||||
expect(secretStorageLabel(pending)).toBe("File (unencrypted)");
|
||||
const caveat = secretStorageCaveat(pending);
|
||||
expect(caveat).toContain("next time a secret is saved");
|
||||
expect(caveat).not.toContain("MCP_INSPECTOR_SECRET_KEY");
|
||||
});
|
||||
|
||||
it("prefers the memory caveat when a memory store somehow carries the flag", () => {
|
||||
// Defensive ordering: `plaintext` is meaningless for memory, and the
|
||||
// durability loss is the more consequential of the two statements.
|
||||
|
|
|
|||
|
|
@ -289,6 +289,27 @@ describe("useInitialConfig", () => {
|
|||
["null", null],
|
||||
["an unknown kind", { kind: "vault", durable: true }],
|
||||
["a missing kind", { durable: true, path: "/x" }],
|
||||
// The dangerous one: `kind` alone passed the old check, and a missing
|
||||
// `plaintext` is falsy, so it rendered as the quiet *encrypted* file —
|
||||
// the most misleading thing this footer can say, produced by the absence
|
||||
// of information rather than by anything the backend claimed.
|
||||
["a file descriptor with nothing but a kind", { kind: "file" }],
|
||||
[
|
||||
"a file descriptor missing its path",
|
||||
{ kind: "file", reason: "fallback", durable: true, plaintext: false },
|
||||
],
|
||||
[
|
||||
"a file descriptor missing plaintext",
|
||||
{ kind: "file", reason: "fallback", durable: true, path: "/x" },
|
||||
],
|
||||
[
|
||||
"a descriptor with an unknown reason",
|
||||
{ kind: "keyring", reason: "vibes", durable: true },
|
||||
],
|
||||
[
|
||||
"a descriptor with a non-boolean durable",
|
||||
{ kind: "memory", reason: "fallback", durable: "no" },
|
||||
],
|
||||
])("rejects %s", async (_label, value) => {
|
||||
const fetchFn = vi
|
||||
.fn()
|
||||
|
|
|
|||
Loading…
Reference in a new issue