Commit Graph
3 Commits
Author SHA1 Message Date
rUvandClaude 82595ec557 dream(security): #3151 sliding-window reset for maxToolCallsPerTurn (evaluated, ACCEPT) (#3152)
* dream(security): #3151 sliding-window reset for maxToolCallsPerTurn (evaluated, ACCEPT)

Follow-up to PR #3139 (2026-08-31, unmerged): the opt-in MCP policy
enforcer's maxToolCallsPerTurn was a permanent session-lifetime cumulative
counter that never reset, explicitly disclosed as unsafe to enable by
default. Tonight's research (5 parallel roles) converged on a wall-clock
sliding window as the correct fix, corroborated by the MCP spec's own
silence on rate-limit mechanism, SEP-2567's removal of the session
concept, Cloudflare's production sliding-window-counter data, and how
FastMCP/PolicyLayer solve the same problem in the MCP ecosystem.

- checkAndRecordCall/evaluateToolCall now take an injectable `now`
  (defaults to Date.now(), zero production behavior change at the one
  real call site in mcp-server.ts).
- New McpPolicy.turnWindowMs field (default 60000ms); shipped in
  .harness/mcp-policy.json alongside the existing maxToolCallsPerTurn.
- 30/30 tests passing (24 pre-existing unmodified + 6 new). Broader
  MCP-suite sweep: 52/56 (4 failures are pre-existing unbuilt-sibling-
  package environmental gaps, unrelated to this diff).
- Independent adversarial critique: CONFIRMED-WITH-CAVEATS. Two minor
  findings (untested exact window boundary; audit-log timestamp cosmetic
  desync from the injected clock) fixed before this commit.

Full report: docs/dream-cycle/dream-gist-2026-09-01.md

* dream(security): #3151 update LEDGER.md for 2026-09-01

Ledger row for tonight's dream-cycle: sliding-window reset for
maxToolCallsPerTurn (PR #3152, stacked on #3139).

* dream(security): #3151 address ruvnet's PR #3152 review (round 1)

Retargeted PR #3152's base to main: dream/2026-08-31-security is not
main/develop, so every required CI workflow (ci.yml, integration-tests.yml,
cve-audit.yml, v3-ci.yml, verification-pipeline.yml) is configured to
trigger only on PRs targeting main/develop and structurally never ran on
either #3139 or this stacked PR's head, regardless of what was pushed.
This is a repo-wide trigger-configuration fact, not fixable by a commit.

Also addresses the review's other concrete asks:
- Built the two sibling packages disclosed as unbuilt (@claude-flow/cli-core,
  @claude-flow/neural) via tsc. Broader MCP-suite sweep improves from 52/56
  to 201/204 -- remaining 3 failures confirmed (independently, by testing a
  raw ::1 bind outside any test) to be EAFNOSUPPORT: IPv6 loopback binding
  unsupported at the container/OS level in this sandbox, unrelated to this
  diff and not fixable by any code change here.
- Added an integration test exercising the real stdio dispatcher
  (MCPServerManager.handleMCPMessage) through a full deny -> expiry -> allow
  cycle with fake timers, proving the fix holds without bypassing audit
  logging or the opt-in flag -- the review's specific ask, previously only
  covered at the direct evaluateToolCall() call level.
- Strengthened documentation (McpPolicy.maxToolCallsPerTurn JSDoc and
  .harness/mcp-policy.json's own field comment): explicit that despite the
  field name this is wall-clock rate limiting, not a literal
  per-conversational-turn counter -- MCP has no protocol-level turn concept.

31/31 policy-enforcer tests passing (was 30/30; +1 dispatcher-level test).

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-09-14 22:20:33 +00:00
ruv 5acc51d74c feat(metaharness): .harness/manifest.json — fingerprint security-critical files (iter 32)
Companion to iter-30's mcp-policy.json. Hand-authored Merkle-style
manifest pinning the sha256 of the two security-critical files that
mcp-policy.json governs:

  .harness/mcp-policy.json   → sha256 (iter-30's MCP governance policy)
  .claude/settings.json      → sha256 (declares the claude-flow MCP server)

POSTURE IMPROVEMENT (verified end-to-end against metaharness@0.1.14)

                          BEFORE iter 32      AFTER iter 32
  composite oia-audit     low                 CLEAN ★
  threat-model worst      low (unpinned-deps  info (only "no issues
                          dropped iter 31)    found" info note)
  mcp-scan findings       0 (iter 31 cleared) 0
  L7 governance text      "mcp-policy.json    "mcp-policy.json
                          (witness missing)"  (witness missing)"

★ Composite worst severity now CLEAN — ruflo's audit pipeline reports
  zero non-info findings. iter-7 + 27 + 30 + 31 + 32 closed the full
  loop: instrumentation found a HIGH, fix-cycle drove it down to
  clean over five iterations.

THE WITNESS GAP (intentionally not closed in this iter)

The OIA "implementation" note still reads "mcp-policy.json (witness
missing)". A witness.json would require Ed25519 signing the manifest,
which needs a WITNESS_SIGNING_KEY (64-char hex). Ruflo's existing
brain-signing-key in GCP is in a different format (89 chars). Three
options documented in .harness/README.md:

  1. Provision a new GCP secret `witness-signing-key` (32 random
     bytes hex). Requires explicit user authorization — creates a
     new long-lived secret. NOT done in this iter.
  2. Use a hardware key (YubiKey / Sigstore ephemeral identity).
  3. Skip the witness — keep the "(witness missing)" note. Threat
     model + mcp-scan are already CLEAN; the witness only signs the
     manifest, doesn't add new security controls.

Current state is option 3 by default. Switch to (1) or (2) when
external manifest-verification becomes needed.

SMOKE STEP 17u
- manifest.json exists + parses
- Both security-critical files fingerprinted with valid 64-hex sha256
- README.md exists + documents witness-signing-key option
- ADR-150 anchor present in README

Smoke: 36 → 37. Fleet: 33/33.

Co-Authored-By: RuFlo <ruv@ruv.net>
2026-06-16 16:03:50 -04:00
ruv 8d3900a93b fix(metaharness): close no-policy HIGH finding — ruflo gets an mcp-policy.json (iter 30)
The iter-27 npx-argv fix surfaced a real, previously-hidden HIGH-severity
finding from `harness threat-model .`:

  [high] no-policy: MCP server with no policy

Ruflo's .claude/settings.json declares the `claude-flow` MCP server,
but had no .harness/mcp-policy.json — the threat model correctly
flagged that as ungoverned execution.

THE POLICY (.harness/mcp-policy.json — new file, 32 lines)
- defaultDeny: true             (ADR-022 posture — refuse ungranted capabilities)
- allowShell: false             (claude-flow MCP server does NOT expose shell; Bash is native CC)
- allowNetwork: false           (network access via memory/embeddings is internal, not raw fetch)
- allowFileWrite: false         (file I/O via AgentDB abstraction, not raw write)
- requireApprovalForDangerous: true
- auditLog: true                (enterprise trust signal)
- toolTimeoutMs: 600_000        (10 min per tool call, bounded)
- maxToolCallsPerTurn: 200      (bounds runaway loops)
- dangerousPatterns: regex list for Bash(rm/sudo/curl-pipe-sh/etc.)
- approvedServers: ["claude-flow"]
- $comment, rationale, references: cross-linked to ADR-150 + upstream

MEASURED IMPROVEMENT (verified end-to-end against metaharness@0.1.13)
                          BEFORE iter 30        AFTER iter 30
  threat-model worst      HIGH                  LOW (just unpinned-deps)
  threat-model verdict    HIGH                  CLEAN
  L7 governance alignment partial               FULL ★
  L8 audit signal         off                   auditLog: true
  MCP policyPath          null                  .harness/mcp-policy.json

★ Major OIA layer transition. Ruflo went from "partial" L7 governance
  to "full" by introducing one 32-line JSON file.

ARCHITECTURAL NOTES
The policy reflects ruflo's REAL posture, not an aspirational one. The
claude-flow MCP server doesn't actually expose shell/network/file-write
primitives — those operations happen at the native Claude Code tool
layer (Bash / Write / Edit / WebFetch), governed by Claude Code's own
permission system. The MCP layer trades in higher-level abstractions
(memory_*, hooks_*, agentdb_*, embeddings_*). So denying the three
elevation flags at the MCP layer is honest — there's nothing in the
MCP server's tool surface that needs them.

The HIGH finding's deeper meaning was "this surface is ungoverned".
With the policy file present + default-deny + audit-log, the surface
is now governed at the right layer.

SMOKE STEP 17t (anti-regression)
- File must exist + parse as JSON
- defaultDeny, auditLog, requireApprovalForDangerous all === true
- toolTimeoutMs + maxToolCallsPerTurn both positive numbers
- ADR-150 anchor present in policy contents

Smoke: 35 → 36. Fleet: 33/33. Three audits clean. tsc clean.

The audit pipeline drove its own remediation: iter-7's oia-audit found
the HIGH, iter-30 fixed the underlying cause. The system can now
self-improve based on its own static-analysis output.

Co-Authored-By: RuFlo <ruv@ruv.net>
2026-06-16 15:51:12 -04:00