Skip to content

fix(scanner): ramparts scan fails closed on garbled tools.json or scan error - #674

Merged
Dumbris merged 2 commits into
mainfrom
fix/mcp-2443-ramparts-fail-closed
Jun 15, 2026
Merged

Dumbris merged 2 commits into
mainfrom
fix/mcp-2443-ramparts-fail-closed

Conversation

@Dumbris

@Dumbris Dumbris commented Jun 15, 2026

Copy link
Copy Markdown
Member

Problem (MCP-2443, [SEC] HIGH)

The Ramparts docker scanner failed OPEN: a broken/garbled input or a ramparts failure was reported as a clean, zero-finding scan, silently defeating the security gate.

Two root causes:

  1. mcp-replay.py returned [] tools when /scan/source/tools.json was missing / empty / garbled / wrong-shape → Ramparts completed a handshake against an empty tool list and emitted a "clean" report.
  2. entrypoint.sh masked the ramparts exit code (|| true) and accepted any non-empty file ([ -s REPORT ]) as success → a failed scan that wrote a non-empty error JSON was treated as a successful report.

Compounding it: the Go runner ignores the container exit code (docker.go RunScanner returns nil for a non-zero exit) and marks a scan failed only when no readable report exists. So exit 1 alone is not enough — the engine reads whatever report file is present.

Fix — fail CLOSED

  • mcp-replay.py: load_tools() now raises ToolsLoadError and the shim exits non-zero serving no frames when tools.json is unreadable / empty / invalid JSON / wrong-shape / yields zero usable tools. Ramparts then sees a dead endpoint instead of an empty tool list. A partially-garbled file with ≥1 real tool still scans.
  • entrypoint.sh: captures the ramparts exit code, then validates the output is a genuine Ramparts report (top-level security_issues object + yara_results array — the same shape isRampartsOutput() probes). On any failure it deletes the report so the engine finds no output and records the scanner as failed, instead of parsing a stale/error payload as 0 findings. A non-zero ramparts exit with a valid report is kept (findings/offline-LLM signal that way — discarding it would lose real detections).

Acceptance

Criterion Covered by
Garbled/empty tools.json → non-zero exit, scan failed (not clean) mcp-replay_test.py: test_{empty_file,garbled_json,wrong_shape,empty_tool_list,missing_tools_file}_fails_closed
Non-zero ramparts exit / error payload → propagated as scan failure entrypoint_test.sh: error_payload_nonzero_fails, error_payload_rc0_fails, empty_report_fails, garbled_report_fails
Valid tools.json with a real finding still scans + reports mcp-replay_test.py: test_partial_garble_with_real_tool_still_scans; entrypoint_test.sh: valid_*_kept

Verification (local)

$ python3 docker/scanners/ramparts/mcp-replay_test.py   →  11/11 passed
$ sh docker/scanners/ramparts/entrypoint_test.sh        →  7 passed, 0 failed
$ shellcheck docker/scanners/ramparts/entrypoint*.sh    →  clean (exit 0)

Docs updated: docs/features/scanner-images.md (fail-closed section).

Notes

  • No Go changes; behavior is enforced in the scanner container assets. The Dockerfile COPYs only entrypoint.sh/mcp-replay.py, so the new *_test.sh/*_test.py files don't enter the image.
  • Follow-up (Release lane): wire mcp-replay_test.py + entrypoint_test.sh into scanner-images.yml CI (they currently run locally only).

Related MCP-2443

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 15, 2026 •

Copy link
Copy Markdown

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@github-actions

github-actions Bot commented Jun 15, 2026 •

Copy link
Copy Markdown
Contributor

📦 Build Artifacts

Workflow Run: View Run
Branch: fix/mcp-2443-ramparts-fail-closed

Available Artifacts

  • archive-darwin-amd64 (28 MB)
  • archive-darwin-arm64 (25 MB)
  • archive-linux-amd64 (16 MB)
  • archive-linux-arm64 (14 MB)
  • archive-windows-amd64 (28 MB)
  • archive-windows-arm64 (25 MB)
  • frontend-dist-pr (0 MB)
  • installer-dmg-darwin-amd64 (21 MB)
  • installer-dmg-darwin-arm64 (19 MB)

How to Download

Option 1: GitHub Web UI (easiest)

  1. Go to the workflow run page linked above
  2. Scroll to the bottom "Artifacts" section
  3. Click on the artifact you want to download

Option 2: GitHub CLI

gh run download 27536483444 --repo smart-mcp-proxy/mcpproxy-go

Note: Artifacts expire in 14 days.

…n error

The Ramparts scanner reported a broken run as a clean, zero-finding scan
(fail-open), defeating the security gate:

- mcp-replay.py served `[]` tools when /scan/source/tools.json was
  missing/empty/garbled/wrong-shape, letting Ramparts emit a spurious
  clean report.
- entrypoint.sh masked the ramparts exit code (`|| true`) and accepted
  any non-empty file as success, so a failed scan that wrote a non-empty
  *error* JSON was treated as a clean report. The Go runner ignores the
  container exit code, so a non-zero exit alone never marked the scan
  failed.

Fix (fail CLOSED):
- mcp-replay.py: raise ToolsLoadError and exit non-zero (serving no
  frames) on unreadable/empty/invalid/wrong-shape tools.json or zero
  usable tools, so Ramparts sees a dead endpoint instead of an empty
  tool list.
- entrypoint.sh: validate the captured output is a genuine Ramparts
  report (top-level security_issues object + yara_results array, the
  shape isRampartsOutput() probes). On failure, DELETE the report so the
  engine finds no output and records the scanner as failed. A non-zero
  ramparts exit with a valid report (findings/offline-LLM) is kept.

Adds runnable tests: mcp-replay_test.py fail-closed cases and a new
entrypoint_test.sh that stubs ramparts to cover every report/exit combo.
Docs updated in docs/features/scanner-images.md.

Related MCP-2443
@Dumbris
Dumbris force-pushed the fix/mcp-2443-ramparts-fail-closed branch from 9fc68ab to b651be5 Compare June 15, 2026 06:35
@Dumbris

Dumbris commented Jun 15, 2026

Copy link
Copy Markdown
Member Author

codex review (gpt-5.5) → REQUEST_CHANGES (independently re-verified)

Blocking bug: the fail-closed gate in entrypoint.sh checks data.get('security_issues') is None (presence, not type). An error payload like {"security_issues":"scan failed","yara_results":[]} (string, not object) passes the gate and is kept as a valid clean report — contradicting the PR's own doc ("a top-level security_issues object").

Fix: require isinstance(data.get('security_issues'), dict) (and similarly type-check the other expected-object fields). Add a test for the malformed-string payload.

Re-review (MCP-2443) found the fail-closed gate checked
`security_issues is None` — presence only, not type. An error payload like
{"security_issues":"scan failed","yara_results":[]} has the key present but
the wrong type, so it passed the gate as a clean scan = fail-open survives.

entrypoint.sh now requires `security_issues` to be an object (dict) and
`yara_results` an array, matching the real Ramparts report schema
({security_issues{tool_issues,...}, yara_results[]}). Anything else fails
CLOSED (report deleted -> scanner marked failed).

Adds entrypoint_test.sh cases: a string `security_issues` and a string
`yara_results` payload both assert the scan is marked failed, not clean.

Related MCP-2443

Co-Authored-By: Paperclip <[email protected]>
@Dumbris

Dumbris commented Jun 15, 2026

Copy link
Copy Markdown
Member Author

Re-review fix pushed (type-confusion gap closed)

Thanks — confirmed real. The fail-closed gate was presence-only (security_issues is None), so {"security_issues":"scan failed","yara_results":[]} passed as clean.

Fix (ca59f70c): entrypoint.sh now type-checks the report shape — security_issues must be an object (dict) and yara_results an array (list), matching the real Ramparts schema ({security_issues{tool_issues,...}, yara_results[]}). Anything else fails CLOSED (report deleted → scanner marked failed).

TDD: entrypoint_test.sh adds string_security_issues_fails and string_yara_results_fails — both assert the scan is marked failed (report removed), not clean.

Verification: entrypoint 9/9, shim 11/11, shellcheck clean. Pushed to the same branch; CI + review re-trigger. QA re-dispatched at head ca59f70c.

@mcpproxy-gatekeeper mcpproxy-gatekeeper Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

codex re-review ACCEPT (gpt-5.5): fail-closed gate now type-checks security_issues as dict + yara_results as list; string/garbled/error payloads rejected (results.json deleted); clean object reports still pass; no regression. Fixes the prior REQUEST_CHANGES.

@Dumbris
Dumbris merged commit 5e76d85 into main Jun 15, 2026
41 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.

2 participants