Skip to content

[MCP contract security 1/2] Review complete tool contracts before trust - #803

Open
salmonumbrella wants to merge 9 commits into
runkids:mainfrom
salmonumbrella:feat/mcp-rugsnare-security
Open

salmonumbrella wants to merge 9 commits into
runkids:mainfrom
salmonumbrella:feat/mcp-rugsnare-security

Conversation

@salmonumbrella

@salmonumbrella salmonumbrella commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Type

  • Bug fix
  • Small improvement (docs, typo, minor refactor)
  • Feature proposal (proposals/ only)
  • Approved feature or large change — maintainer approval remains pending

Linked Issue

Refs #789, specifically the RugSnare comment, and design note #802. This covers MCP contract protection, not the entire six-part issue.

What changed

  • Extend existing tool pinning with complete, bounded contract snapshots, split hashes, conservative directional changes and descriptor audits. Incomplete or ambiguous inventories fail rather than approving a prefix.
  • Replace automatic first trust with explicit approval bound to the reviewed inventory, connection identity, scope and current store. CLI and dashboard share the same locked persistence path.
  • Harden HTTP/RPC parsing, redirects, pagination, stdio writes and credential-safe diagnostics. Add regression/property tests, isolated runbooks and command documentation.
  • Keep localized dashboard diagnostics readable in Persian while preserving escaping for controls supplied by MCP servers; add focused regressions for numeric secret echoes, disabled entries, stdio logs and credential-bearing project roots.

Why

A server can change the instructions or schema it advertises after initial setup. Existing hashes warn about some changes but do not show the full contract or bind acceptance to the exact inventory reviewed. Users need to inspect the change before saving trust.

Usage

skillshare mcp check example --live --json
# Inspect the complete contract and copy its revision, then explicitly approve:
skillshare mcp check example --live --accept-tools --revision <reviewed-revision>
skillshare mcp check example --live --strict-tools

For same-name servers under mcp.projects, select --root <configured-path>; --root '' selects this config's own server list. Project mode remains -p. In the dashboard, Review live tools opens an inert dialog; Probe live tools starts the check and Trust this inventory explicitly approves one returned scope/revision.

Baseline approval requires environment/header/bearer declarations to use fromEnv. Referenced values and ambient environment are not process attestation. A stale second probe or concurrent source/store change refuses acceptance. Otherwise-valid non-sensitive literals remain manageable and probeable. Every nonempty resolved reference value is treated conservatively as confidential: an identity substring match can refuse static/live/draft checks even when accidental. Changing only the reference syntax does not resolve a matching value; remove the overlap from identity-bearing material.

Threat model and limits

This is a point-in-time advertised-contract check. It cannot detect malicious implementation behind an unchanged contract, attest executable bytes, block individual calls or quarantine a native client's runtime. Unsigned local state does not authenticate a deliberate edit by an attacker with write access. Optional externally anchored signing is the second slice of this series.

Descriptor audits are review signals, not proof of safety. Known configured credential echoes are refused before trust fingerprints; arbitrary unconfigured secrets remain outside that guarantee. Full snapshots may contain sensitive text and remain private local state. See the security note.

Prior art

Independently authored native Go, informed primarily by RugSnare (Apache-2.0) and conceptual requirements from Tirith (AGPL-3.0). No source, translated code, fixtures or golden vectors from either project are copied into this contribution. The native hash profile preserves numeric lexemes and all array order; no PIN-SPEC/RFC 8785 interoperability is claimed.

Verification

Current candidate: 47646362cfebcb4073a631b47341bb57871ed5d1, rebased onto upstream main at b97206e9465c78d4afe674f782a3326cab8b3ace. Current-head upstream CI is green, and Codex found no new issues; roborev-ci is still pending.

This rework fixes the three open Codex threads. Source review also fixed case-insensitive HTTP media-type handling, symlink-target binding for stdio working directories, and client-selection fields spuriously staling connection identity; it removed a rendered copy-only dashboard test and corrected private tool-pin state descriptions in all existing translated file maps. The test-quality review consolidated duplicate coverage, repaired invalid fixtures, and narrowed CLI integration to explicit revision approval and persistence.

One focused MCP test command passed on interim commit 4b2de1ba, before the later test consolidations and the MIME/symlink fixes:
go test ./internal/mcp -run 'TestCaptureContractRejectsNumericCredentialLexemes|TestToolBaselineRejectsNumericCredentialsInCurrentAndStoredSnapshots|TestNumericConnectionCredentialRejectedBeforeProbeAndFingerprint|TestLiveStrictToolsSkipsDisabledProjectEntry|TestCheckProjectScopePreservesControlsAndRedactsCredentials' -count=1
No tests or builds ran after that interim check; current-head Go, UI and website checks remain for upstream CI.

Earlier CI and source reviews applied to candidate 3d01ea05658cf3242e6d8690fc8a5c258740f50f on base d58bc0dd4d5d0a90a3ec41674f975510a0ac2ba6; those results do not validate this rebased head. That candidate's Nix/check run 42631392063 and test run 42631392217 passed, with Docker online and redteam-signal skipped.

Not run locally: full Go suites, make check, UI tests/typecheck/lint/build, browser QA, website build, runbooks, E2E or Windows tests. The single allowed focused MCP test above was run once. No local Docker or PostgreSQL checks were performed.

Hegel remains in a separate test-only module; CI requests hegel.dev/go/hegel@latest. It adds no production runtime dependency.

Checklist

  • I've read CONTRIBUTING.md, including its AI-assisted contributions section
  • I've reviewed every line of the diff and can explain it — human review pending
  • Tests included and passing (make check) — authored, execution pending
  • No unrelated changes in the diff
  • Scope is focused — contract review and explicit trust; signing is a separate slice

@salmonumbrella
salmonumbrella marked this pull request as ready for review November 8, 2026 21:53
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-11T10:09:13.626866Z 4764636 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector 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 Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 941d3f806d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +341 to +344
switch v := v.(type) {
case string:
return has(v)
case map[string]any:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Reject numeric credential echoes before exposing contracts

When a fromEnv credential is a numeric string such as 123456, an MCP server can echo it as a JSON number in _meta or a schema default. contractJSON preserves that value as json.Number, but this switch ignores numbers, so captureTool succeeds, exposes the credential in the new CLI/API snapshots, and allows it into an approved baseline. The same omission exists in containsLiveSecret in check_live.go, allowing numeric identity material through its credential check too. Check numeric lexemes against known credentials in both helpers before exposing or fingerprinting them.

AGENTS.md reference: AGENTS.md:L36-L36

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in dbcc5726: both contractHasSecret and containsLiveSecret inspect exact json.Number lexemes before contract capture or fingerprinting. Numeric capture coverage is retained in TestCaptureContractKnownShortSecretsInDecodedKeysAndValues; the live-probe path remains covered by TestNumericConnectionCredentialRejectedBeforeProbeAndFingerprint. Current-head CI is pending.

Comment thread internal/mcp/check_live.go Outdated
Comment on lines +70 to +71
if opts.StrictTools {
result.Findings = append(result.Findings, CheckFinding{Level: "error", Check: "tool-change", Message: "strict tool checking requires a complete live observation"})

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Exempt disabled entries from strict observation failures

For a project containing a disabled: true switch created through the dashboard’s off toggle, liveSkipReason correctly skips the entry, but this branch turns that expected skip into an error whenever --strict-tools is set. Consequently, strict checks fail even when every enabled server has an unchanged approved contract. The disabled entry cannot acquire a baseline to clear the error because it intentionally has no connection fields. Exempt disabled entries from the complete-live-observation requirement.

AGENTS.md reference: AGENTS.md:L36-L36

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in dbcc5726. Strict live checking adds a completeness error only for a skipped server that is not disabled, so intentionally disabled project entries retain the expected skip behavior. TestLiveStrictToolsSkipsDisabledProjectEntry covers it. Current-head CI is pending.

@salmonumbrella
salmonumbrella marked this pull request as draft November 9, 2026 11:32
@salmonumbrella
salmonumbrella force-pushed the feat/mcp-rugsnare-security branch from 941d3f8 to 3d01ea0 Compare November 9, 2026 14:06
@salmonumbrella

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 3d01ea0565

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector 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 Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3d01ea0565

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread internal/mcp/check.go Outdated
}
for i := range report.Servers {
result := &report.Servers[i]
result.Name, result.Project = redactor.redact(result.Name), redactor.redact(result.Project)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve lossless project roots in check results

For an mcp.projects folder added through the dashboard whose name contains a legitimate format character such as Persian ZWNJ (U+200C), redactor.redact replaces that character with the literal \u200c sequence in project. MCPContractReview.tsx:168 then sends this display-escaped value as the approval root, so Check's exact source.Projects[root] lookup rejects an otherwise valid reviewed inventory; useMCPCheck.ts:7 also stops associating static findings with that project. Preserve a lossless scope identifier for these consumers and escape it only when rendering, while retaining credential redaction for refusals.

AGENTS.md reference: AGENTS.md:L36-L36

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 4b2de1ba. Check results preserve exact project-scope bytes unless they contain a known credential, in which case review is refused and the value is redacted. The dashboard matches and submits the exact root while escaping it for display. Coverage is in TestCheckProjectScopePreservesControlsAndRedactsCredentials and associates and approves the exact project root while escaping it for display. Current-head CI is pending.

Extend existing tool pinning with complete bounded snapshots, conservative
contract differences and credential-safe descriptor audits. Bind approval to
the reviewed inventory, connection identity, scope and current source/store.

Share explicit revision-bound acceptance across CLI and local dashboard API,
harden discovery transports and preserve full exact-number review text.
Document threat boundaries and independently authored prior-art provenance.

Tests are authored but unrun: required local devcontainer is unavailable.
Remote CI and review must verify compilation and runtime behavior.
Preserve credential-free project root identifiers exactly so dashboard checks associate the right project and approvals submit the selected scope. Continue redacting credential-bearing roots after refusing their review, and escape controls at presentation boundaries.

The rebased feature already rejects numeric credential lexemes in both contract and live checks and excludes disabled project entries from strict observation failures; their regression coverage remains in the feature commit.
Remove unreachable and duplicated scenarios, retain unique credential and scope checks, and use valid server fixtures. Exercise real control runes in JSON output and consolidate dashboard refusal and localization cases.
Combine remaining scope, persistence, status and contract cases into shared tables while preserving distinct behavior checks and reachable fixtures.
Resolve the stdio working directory before launch and bind that same path into the review identity, so retargeted symlinks cannot reuse approval. Reject unresolved directories before starting a server.

Parse HTTP media types to handle case and parameters in event streams and discovery errors. Exercise both cases and remove the disclaimer-only UI test.
Describe the complete contract snapshots stored in tool-pins.json and warn that their text may be sensitive. Keep the existing translated file maps consistent.
Fingerprint the explicit transport, credential references, tool policy and native options without target selection or disabled state. Client selection changes can then retain an unchanged contract approval.
Keep the live review, explicit revision approval and fresh unchanged check as the CLI integration boundary while leaving detailed drift and logging coverage to their owning tests.
Remove the unsupported disabled entry with an active connection while retaining identity and approval coverage for valid target changes.
@salmonumbrella
salmonumbrella force-pushed the feat/mcp-rugsnare-security branch from 3d01ea0 to 4764636 Compare November 11, 2026 10:02
@salmonumbrella

Copy link
Copy Markdown
Contributor Author

@codex review

The requested fixes to all three open findings are in this rebased head: 47646362cfebcb4073a631b47341bb57871ed5d1. I replied on each thread. Please review the current head, including the MIME parsing, stdio working-directory binding, and connection identity scope changes. Current-head CI is pending.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 47646362cf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@salmonumbrella

Copy link
Copy Markdown
Contributor Author

@runkids ready

@runkids runkids added feature New feature or request pending mcp MCP server and MCP configuration security Supply-chain and malicious-skill detection labels Nov 15, 2026
@runkids

runkids commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

Thanks for all the work you've put into these. A lot of large PRs have arrived at once, more than I can take in right now, so I need to go through them slowly. I can't promise a date, but I'll get to them.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request mcp MCP server and MCP configuration pending security Supply-chain and malicious-skill detection

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants