fix(security): sanitize session id to block path traversal in grounding-mcp session store#102
Merged
Merged
Conversation
The read verbs (grounding_advance, grounding_guardrail_check,
claim_evaluate_from_session) pass a client-controlled sessionId straight
into loadSession/sessionExists, which built the file path via
join(sessionsRoot(), `${id}.json`) with NO sanitisation. A client could
send sessionId "../../../../etc/hostname" to read or probe arbitrary
<path>.json files outside the sessions root.
Add sanitizeSessionId() mirroring the existing sanitizeVerdictId() guard in
solution-verdict.ts (collapse non [A-Za-z0-9._-] to "_", path.basename,
reject ""/"."/".."), and call it inside pathFor() so loadSession,
saveSession and sessionExists all inherit the guard. Server-generated ids
(gs-<slug>-<base36>) only use safe characters, so legitimate sessions
round-trip unchanged.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The grounding-mcp session store derived a session file path from a client-controlled
sessionIdwith no sanitisation, allowing path traversal (arbitrary<path>.jsonread and file-existence probing) outside the sessions root. This applies the same guard the sibling verdict store already ships.Finding fixed
sessionId(packages/grounding-mcp/src/session-store.ts:25-27,pathFor). The read verbsgrounding_advance(server.ts:146),grounding_guardrail_check(server.ts:167), andclaim_evaluate_from_session(server.ts:286) pass the raw MCP-client string intoloadSession/sessionExists, which built the path viajoin(sessionsRoot(), ${id}.json). A client sendingsessionId: "../../../../etc/hostname"escapedsessionsRoot(). Guard added: a newsanitizeSessionId()(session-store.ts:36) collapses any character outside[A-Za-z0-9._-]to_, appliespath.basename, and rejects empty /./.., mirroring the existingsanitizeVerdictId()insolution-verdict.ts:88. It is called insidepathFor()(session-store.ts:55) soloadSession,saveSession, andsessionExistsall inherit the guard. Server-generated ids (gs-<slug>-<base36>) only contain safe characters, so legitimate sessions round-trip unchanged.Verification
npx tsc --noEmitinpackages/grounding-mcp: exit 0, no type errors.npx vitest run tests/roundtrip.test.ts: 7/7 passed, confirming legitimate session ids still save and load correctly through the hardenedpathFor().Refs: 2026-05-30 security audit (HIGH)