feat(mcp): MCP-SAN + MCP-COV hardening#76
Open
CoderMungan wants to merge 1 commit intoActiveMemory:mainfrom
Open
feat(mcp): MCP-SAN + MCP-COV hardening#76CoderMungan wants to merge 1 commit intoActiveMemory:mainfrom
CoderMungan wants to merge 1 commit intoActiveMemory:mainfrom
Conversation
Implements sanitization layer (MCP-SAN ActiveMemory#49) and coverage expansion (MCP-COV ActiveMemory#50) for the MCP server. Sanitization: - Add internal/sanitize package: Content, Reflect, SessionID, StripControl, truncate helpers - Add internal/config/sanitize constants (NullByte, DotDot, etc.) - Add internal/config/regex/sanitize compiled regexes - Add MaxSourceLimit, MaxContentLen, MaxNameLen, MaxQueryLen, MaxCallerLen, MaxURILen constants to internal/config/mcp/cfg - Add InputTooLong error constructor in internal/err/mcp - Add mcp.err-input-too-long and mcp.err-unknown-entry-type YAML keys - Apply sanitize.Content in extract EntryArgs and prompt buildEntry - Apply sanitize.Reflect for query, caller, name, URI in all tool/prompt/resource dispatch paths - Cap source limit to MaxSourceLimit in tool handler Coverage: - internal/entity/mcp_session_test.go: 10 tests covering MCPSession lifecycle methods including PendingCount, RecordSessionStart, RecordContextLoaded, RecordDriftCheck, RecordContextWrite, IncrementCallsSinceWrite - internal/mcp/server/server_test.go: 15+ new tests covering notification handling, subscribe/unsubscribe error paths, ctx_remind with active and future-dated reminders, ctx_drift missing-file violations, ctx_complete empty and non-matching query - internal/mcp/proto/schema_test.go: JSON round-trip tests - internal/mcp/server/def/{tool,prompt}/*_test.go: def count tests - internal/mcp/server/{extract,io,out,parse,stat}/*_test.go: unit tests Signed-off-by: CoderMungan <codermungan@gmail.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.
Closes #49, closes #50
Summary
Re-implementation of PR #52 adapted to the current codebase. Addresses
MCP-SAN (#49) sanitization requirements and MCP-COV (#50) coverage
requirements in full.
MCP-SAN (#49) — Sanitization layer
New packages
internal/sanitize:Content,Reflect,SessionID,StripControl,truncateinternal/config/sanitize: string/length constants (NullByte,DotDot,ForwardSlash,Backslash,HyphenReplace,MaxSessionIDLen)internal/config/regex/sanitize: compiled regexes for Markdown structure chars and session ID unsafe charsConfig constants
Added to
internal/config/mcp/cfg:MaxSourceLimit,MaxContentLen,MaxNameLen,MaxQueryLen,MaxCallerLen,MaxURILenError + text
internal/err/mcp:InputTooLong(field, maxLen)constructormcp.err-input-too-longandmcp.err-unknown-entry-typekeys in embed/text and YAMLApplied sanitization
extract.EntryArgs: MaxContentLen guard →InputTooLongerrorextract.SanitizedOpts: sanitizes all option fieldsroute/prompt/entry.buildEntry:sanitize.Contenton every field valueroute/tool/tool.go:sanitize.Contenton content,sanitize.Reflecton query/caller, cap limit toMaxSourceLimitroute/tool/dispatch.go,route/prompt/dispatch.go,resource/dispatch.go:sanitize.Reflectfor name/URI in unknown-branch pathsMCP-COV (#50) — Coverage expansion
New test files (12)
internal/entity/mcp_session_test.gointernal/mcp/proto/schema_test.gointernal/mcp/server/def/tool/tool_test.gointernal/mcp/server/def/prompt/prompt_test.gointernal/mcp/server/extract/extract_test.gointernal/mcp/server/io/write_test.gointernal/mcp/server/out/out_test.gointernal/mcp/server/parse/parse_test.gointernal/mcp/server/stat/stat_test.gointernal/sanitize/sanitize_test.goExtended:
internal/mcp/server/server_test.goAdded 15 new tests covering all COV gaps:
TestServeNotificationIgnored— notification silently consumedTestServeEmptyLines,TestServeParseErrorWriteFailure,TestServeDispatchWriteFailureTestResourcesSubscribeInvalidJSON/EmptyURI,TestResourcesUnsubscribeInvalidJSON/EmptyURITestToolRemindWithActive,TestToolRemindFutureDatedTestToolDriftMissingFileTestToolCompleteEmptyQuery,TestToolCompleteNoMatchTestPromptAddLearningCI
go build ./...✅go test ./...✅ (133 packages, 0 failures)go vet ./...✅golangci-lint run✅ (0 issues)