feat(security): add data flow security with agent hook integration (Spec 027)
Summary
- Add data flow security system that detects and prevents data exfiltration by tracking how data moves between internal tools (Read, databases) and external tools (WebFetch, Slack)
- Support two operating modes: proxy-only (universal, works with any MCP agent) and full mode (with agent hook integration for intercepting agent-internal tool calls like Read, Write, Bash)
- Implement complete hook CLI (
mcpproxy hook install/uninstall/status/evaluate) for Claude Code integration
Key Components
- Classifier (
internal/security/flow/classifier.go): Categorizes tools/servers as internal, external, hybrid, or unknown using name heuristics and config overrides - Content Hasher (
internal/security/flow/hasher.go): SHA256 per-field extraction from JSON for content flow matching without storing raw data - Flow Tracker (
internal/security/flow/tracker.go): Session-scoped origin recording and flow edge detection with configurable policies - Policy Evaluator (
internal/security/flow/policy.go): Configurable actions (allow/warn/ask/deny) with graceful degradation in proxy-only mode (ask→warn) - Session Correlator (
internal/security/flow/correlator.go): Links agent hook sessions to MCP proxy sessions via argument hash matching - Hook CLI (
cmd/mcpproxy/hook_cmd.go): Install/uninstall/status/evaluate commands for Claude Code agent hooks - REST API (
internal/httpapi/hooks.go):POST /api/v1/hooks/evaluateendpoint for hook event processing - Activity Logging: New
hook_evaluationandflow_summaryactivity types with full metadata - Web UI Nudge: Dashboard hint encouraging hook installation when running in proxy-only mode
- Diagnostics: Security coverage recommendation in
mcpproxy doctoroutput - OpenAPI: Updated swagger.yaml with new endpoint, activity filters, and schemas
Architecture
Agent (Claude Code)
├── Internal tools (Read, Write, Bash) ──→ Hook CLI ──→ POST /api/v1/hooks/evaluate
└── MCP tools (call_tool_read/write) ──→ MCP Proxy ──→ Upstream servers
↕
Flow Tracker (session-scoped)
Content hash matching
Policy evaluation
Test plan
- [x] 68/70 TDD tasks complete (2 benchmarks deferred to pre-merge)
- [x] Unit tests: all pass including
internal/security/flow/...(25 tests),internal/httpapi/...,internal/runtime/... - [x] Race detection:
go test -race ./internal/security/flow/...passes cleanly - [x] E2E test: proxy-only flow detection pipeline (
TestE2E_FlowSecurity_ProxyOnlyDetection) - [x] E2E test: hook-enhanced flow detection via HTTP API (
TestE2E_FlowSecurity_HookEnhancedDetection) — verifies deny decision withflow_type=internal_to_external,risk_level=high - [x] API E2E:
test-api-e2e.sh— no regressions (61/71 pass, 10 failures pre-existing) - [x] OpenAPI:
verify-oas-coverage.sh— new endpoint documented - [x] Frontend:
vue-tsc --noEmitpasses cleanly
🤖 Generated with Claude Code
Deploying mcpproxy-docs with
Cloudflare Pages
| Latest commit: |
5f39bb7
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://eaecdcb6.mcpproxy-docs.pages.dev |
| Branch Preview URL: | https://027-data-flow-security.mcpproxy-docs.pages.dev |
📦 Build Artifacts
Workflow Run: View Run
Branch: 027-data-flow-security
Available Artifacts
- archive-darwin-amd64 (26 MB)
- archive-darwin-arm64 (23 MB)
- archive-linux-amd64 (15 MB)
- archive-linux-arm64 (13 MB)
- archive-windows-amd64 (26 MB)
- archive-windows-arm64 (23 MB)
- frontend-dist-pr (0 MB)
- installer-dmg-darwin-amd64 (20 MB)
- installer-dmg-darwin-arm64 (18 MB)
How to Download
Option 1: GitHub Web UI (easiest)
- Go to the workflow run page linked above
- Scroll to the bottom "Artifacts" section
- Click on the artifact you want to download
Option 2: GitHub CLI
gh run download 26145206820 --repo smart-mcp-proxy/mcpproxy-go
Note: Artifacts expire in 14 days.
Code review
Found 3 issues:
- Data race in CheckFlow method — Writing to session fields (LastActivity, ToolsUsed, Flows) while holding only a read lock. Will fail
go test -racewhich is required per CLAUDE.md. Lock type should be upgraded toLock()before mutations at lines 113-120.
https://github.com/smart-mcp-proxy/mcpproxy-go/blob/ec787a497596d4cf66404b813b02cf34730fc0de/internal/security/flow/tracker.go#L80-L123
- Missing FlowService.Stop() in Close() — Runtime.Close() stops OAuth manager and supervisor but never stops the FlowService, leaking background goroutines (sessionExpiryLoop, cleanupLoop). Should follow same pattern established in PR #255 with refreshManager.Stop().
https://github.com/smart-mcp-proxy/mcpproxy-go/blob/ec787a497596d4cf66404b813b02cf34730fc0de/internal/runtime/runtime.go#L535-L570
- Missing SetExpiryCallback registration — FlowService.SetExpiryCallback is defined but never registered during runtime initialization. This breaks flow session summary emission to the activity log, causing EventTypeActivityFlowSummary to never fire. Should register callback after flowService creation (line 210).
https://github.com/smart-mcp-proxy/mcpproxy-go/blob/ec787a497596d4cf66404b813b02cf34730fc0de/internal/runtime/runtime.go#L182-L214
🤖 Generated with Claude Code
- If this code review was useful, please react with 👍. Otherwise, react with 👎.
Opened #299 as a stacked PR with fixes for the 3 issues identified in the code review:
- Race condition in
CheckFlow()—RLock→Lock(writes to session fields require write lock) - Goroutine leak — added
FlowService.Stop()inRuntime.Close() - Missing callback — registered
SetExpiryCallbackso flow summaries emit to activity log
All 34 flow tests pass with -race. Includes 3 regression tests.
🤖 Generated with Claude Code
:warning: Please install the to ensure uploads and comments are reliably processed by Codecov.
Codecov Report
:x: Patch coverage is 63.94453% with 468 lines in your changes missing coverage. Please review.
:loudspeaker: Thoughts on this report? Let us know!
Critic (Codex) review — Dumbris's PR #293 Verdict: request_changes Strengths: The PR includes tests and API/OpenAPI updates for the data-flow security surface, and its main build/unit/e2e jobs shown in the PR checks are otherwise passing. Findings:
- Required checks are not all green:
check-sizefailed in the CLAUDE.md Size Check workflow, job https://github.com/smart-mcp-proxy/mcpproxy-go/actions/runs/26145206887/job/76899082389. Per the pre-merge gate rule, a red check is an automaticrequest_changesuntil fixed or explicitly made non-required by the human gate owner. Provenance check: ok
Critic (Codex) review — Dumbris's PR #293
Verdict: request_changes
Head: 5f39bb726974e38c0e5423e281e9747808094f0e
Strengths: The security direction is relevant to the product scope, but this PR cannot advance while required checks are red.
Findings:
- Required CI is red.
gh pr checks 293 --watch=falsereportscheck-sizefailing at https://github.com/smart-mcp-proxy/mcpproxy-go/actions/runs/26145206887/job/76899082389. Per the pre-merge doctrine, a red required check is an automaticrequest_changesuntil rerun/fixed.
Provenance check: ok
Triage (release-eng PR sweep, MCP-1760) — held, not merged.
- Failing check:
check-size— the diff touches only CLAUDE.md and pushes it over the hard 40,000-char CI gate (mainis already ~39.9k). - Branch is also CONFLICTING with
main(needs rebase). - Owner / next step (@Dumbris): rebase onto
main, then move the Spec 027 doc content out of CLAUDE.md intodocs/and/or a memory file so CLAUDE.md stays under 40k. Oncecheck-sizeis green and conflicts resolved, ping and we'll route to Codex review → Gatekeeper merge.