Skip to content

fix(mcp): enforce session write gate on add_memory/getDocument scoping + input bounds - #1582

Open
Sravanjangam wants to merge 1 commit into
supermemoryai:mainfrom
Sravanjangam:fix/mcp-tool-guards
Open

fix(mcp): enforce session write gate on add_memory/getDocument scoping + input bounds#1582
Sravanjangam wants to merge 1 commit into
supermemoryai:mainfrom
Sravanjangam:fix/mcp-tool-guards

Conversation

@Sravanjangam

@Sravanjangam Sravanjangam commented Aug 22, 2026

Copy link
Copy Markdown

Hi supermemory team 👋 Thanks for building such a great product! While running a security & quality audit of the repo we hit this issue and put together a small, tested fix — details below.

Problem

Four gaps in MCP tools allowed a restricted session to exceed its grants:

  1. add_memory skipped the session write gate its sibling tools apply whenever the caller supplied explicit containerTags.
  2. getDocument fetched any raw document ID with no space scoping — cross-space reads by ID.
  3. fetch-graph-data passed unbounded, non-integer page/limit into the metered backend.
  4. guided-save.prefill was length-unbounded, and whoAmI echoed the transport sessionId into model-visible output.

Part of #1578 (findings M5–M7 + low-severity set).

Solution

Mirror the gate pattern the sibling tools already use, verify document membership server-side before returning data, bound every numeric/string input, and keep credentials out of tool outputs.

Changes

  • tools/add-memory.ts → session write gate applied to explicit containerTags
  • tools/get-document.tscontainerTags membership check returning generic "Document not found"
  • tools/fetch-graph-data.ts → bounded integer coercion of page/limit
  • tools/guided-save.tsprefill capped at 200000 chars
  • tools/who-am-i.tssessionId removed from output

Verification

Fresh from the committed branch: bunx vitest run src/server/auth13/13 pass on this branch base; tsc adds zero new errors vs baseline for all five touched files; Biome clean. Merge note: independent of #1581/#1587 (different files).


Happy to iterate on any of this — feedback and reworks very welcome! 🙏

Environment

  • macOS 26.1 (arm64) · bun 1.4.0 · node v26.7.0
  • vitest 3.2.4 (workspace-pinned) · Biome lint clean
  • Branch fix/mcp-tool-guards — all gates re-run fresh at commit b81b9b4183da

- add_memory: apply the same session write gate as guided-save/
  upload-file; an explicit containerTag previously bypassed RBAC so a
  restricted/scoped-read session could write into any space.
- getDocument: verify the fetched document's containerTags include the
  active space before returning it (get-by-ID bypassed space scoping
  every other read tool applies); generic not-found error avoids an
  existence oracle. Docs without tag metadata can't be checked.
- fetch-graph-data: bound page/limit (int, >=1) like sibling list tools;
  unbounded values flowed straight into a metered backend query and
  were echoed into model context uncapped.
- guided-save: cap prefill at 200k like add_memory content.
- whoAmI: stop echoing the MCP transport session id (bearer-style
  credential) into model-visible output persisted in transcripts.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant