-
Notifications
You must be signed in to change notification settings - Fork 9
Description
The MCP server handlers (internal/mcp/server/handle_*.go) accept
client-supplied input over JSON-RPC and use it with minimal validation.
The validation package has SanitizeFilename and ValidateBoundary
but nothing for content or argument sanitization. entry.Validate only
checks field presence, not content safety.
-
Sanitize session IDs before using in file paths #added:2026-03-21-103412
-
MCP-SAN.1: Add input length limits to all string arguments #priority:high #added:2026-03-15
- Define max lengths in
internal/config/mcp/cfg/(e.g.,MaxContentLen,
MaxNameLen,MaxQueryLen,MaxCallerLen) - Apply length checks early in
handleToolsCall,handlePromptsGet,
handleResourcesRead,handleResourcesSubscribe - Cap
toolRecalllimit to a reasonable upper bound (e.g., 100) - Return
ErrCodeInvalidArgwith a clear message when exceeded
- Define max lengths in
-
MCP-SAN.2: Validate
entryTypeagainst allowlist before use #priority:high #added:2026-03-15- In
toolAddandtoolWatchUpdate, checkentryTypeexists in
entryCfg.ToCtxFilemap before proceeding — return error if not - This prevents writing entries with undefined type mappings
- In
-
MCP-SAN.3: Sanitize content written to
.context/files #priority:high #added:2026-03-15- Content fields (
content,context,rationale,consequences,
lesson,application) are written directly to Markdown files - Strip or escape Markdown structure characters that could corrupt
parsing: entry headers (## [YYYY-), task checkboxes (- [ ],
- [x]), constitution rule format (- [ ] **Never) - Add a
SanitizeEntryContentfunction ininternal/validation - Apply in
toolAdd,toolWatchUpdate, andbuildEntryPrompt
- Content fields (
-
MCP-SAN.4: Sanitize reflected input in error/success messages #added:2026-03-15
params.Namereflected in unknown-prompt/unknown-tool errors
(handle_prompt.go:66,handle_tool.go:120)params.URIreflected in unknown-resource error
(handle_resource.go:104)callerreflected in session-started message
(handle_tool.go:804)- Truncate or strip control characters before including in responses
-
MCP-SAN.5: Add tests for all sanitization paths #added:2026-03-15
- Test that oversized inputs are rejected
- Test that invalid
entryTypevalues are rejected - Test that Markdown injection in content fields is neutralized
- Test that reflected strings are truncated/safe
- Test that
toolRecalllimit is capped