Skip to content

fix: production hardening for MCP server#34

Merged
ApiliumDevTeam merged 3 commits intomainfrom
dev
Mar 12, 2026
Merged

fix: production hardening for MCP server#34
ApiliumDevTeam merged 3 commits intomainfrom
dev

Conversation

@ApiliumDevTeam
Copy link
Collaborator

Summary

  • Prevent command injection in setup-claude (host/port validation, execFileSync)
  • CORS default-deny when allowedOrigins is empty
  • Cap SSE sessions at 50 to prevent connection exhaustion
  • Require Content-Type application/json on POST endpoints
  • Timing-safe bearer token comparison in HTTP transport
  • Graceful shutdown with cached promise, skipSignalHandlers for sidecar
  • Wrap all fetch .json() calls in try/catch for non-JSON responses
  • Validate tags with Array.isArray, cap limit/k to prevent resource exhaustion
  • Word-boundary regex in governance to avoid substring false positives
  • Host validation in config parser for all code paths
  • 20 hardening tests covering all fixes

Test plan

  • npx vitest run extensions/mcp-server/ — 112 tests pass (9 files)
  • npx vitest run extensions/memory-semantic/ — 185 tests pass (10 files)
  • pnpm build — compiles without errors
  • Manual SSE shutdown test — server exits cleanly

- Prevent command injection in setup-claude host validation
- Timing-safe bearer token comparison in HTTP transport
- Graceful shutdown with closeAllConnections + SSE session tracking
- Shutdown guard prevents double SIGINT execution
- Word-boundary regex in governance to avoid substring false positives
- Wrap all bare fetch calls in try/catch for Cortex-down resilience
- Cap cortex_query limit at 500 to prevent abuse
- Add hardening.test.ts covering all fixes (12 tests)
- Prefix unused variable with underscore in test
- Add explicit unknown type annotation to catch clauses
- CORS default-deny when allowedOrigins is empty
- Cap SSE sessions at 50 to prevent connection exhaustion
- Require Content-Type application/json on POST endpoints
- Wrap .json() calls in try/catch for non-JSON 200 responses
- Validate tags with Array.isArray, cap limit/k at 100
- Use execFileSync instead of execSync to avoid shell injection
- Add port validation (NaN, range 1-65535) in setup-claude
- Add host validation in config parser for all code paths
- Cache shutdown promise to prevent concurrent signal races
- Add skipSignalHandlers option to CortexSidecar
- Log sidecar/agent errors to stderr instead of swallowing
- Explicit process.exit after shutdown in both HTTP and stdio modes
- Rewrite hardening tests to exercise production code directly (20 tests)
@ApiliumDevTeam ApiliumDevTeam merged commit 89120c9 into main Mar 12, 2026
4 of 5 checks passed
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