Repository navigation
fix(quarantine): length-prefixed tool approval hash so contracts cannot collide - #1634
Merged
Merged
Conversation
…ot collide The v4 rug-pull hash joined name, description and the normalized input schema with an unescaped '|' and appended the output schema only when present, so (D, I, O) and (D+"|"+I, O, none) shared one hash: an approved tool could switch to the second contract and stay approved (#1606). Hash schema v5 (storage.UnambiguousHashSchemaVersion) length-prefixes every field, encodes an absent output schema explicitly and domain-separates the hash. The v4 formula is kept as calculateToolApprovalHashV4 for migration: - an approved v4 record is re-baselined without review only when its v4 ApprovedHash covers the stored contract and that contract equals the live one field by field; anything else is marked changed (no mass re-review, no collision carried across the upgrade); - a stranded v4 pending record still promotes on a baseline pass when its recorded contract equals the live one; - the legacy-sibling pre-RT-03 check uses the v4 formula it was written with. The output-schema wildcard of #1591 is already limited to records below storage.OutputSchemaHashSchemaVersion; new tests pin that a v4 record that gains an output schema is held as changed across the v5 upgrade, in manual and scan trust modes.
- A v4 record held because its ApprovedHash does not cover the stored snapshot no longer records that snapshot as Previous*, so a later pass cannot "revert" to it and approve it. - Legacy collapsed siblings: a v4 sibling approves the live contract only when its v4 hash covers its stored contract and that contract is exactly the live one (an empty description is declared on v4, so an unchanged empty-description tool still adopts); the pipe-joined v3/legacy hash shortcuts only count when the sibling's stored contract does not contradict the live one, so a colliding contract or an added output schema is never adopted.
Deploying mcpproxy-docs with
|
| Latest commit: |
05f0dc3
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://aa660f02.mcpproxy-docs.pages.dev |
| Branch Preview URL: | https://fix-1606-1591-approval-hash.mcpproxy-docs.pages.dev |
…ter the v5 upgrade A changed record whose approved contract had an empty description was only ever restored by the hash match; with the v5 formula its v4 ApprovedHash no longer equals the live hash, so a genuine revert stayed held. An empty PreviousDescription now counts as the declared description when the ApprovedHash (v5 or v4) is the hash of the recorded previous contract; the previous fields are still compared one by one with the live contract, so a contract that only collides under v4 stays held.
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Contributor
📦 Build ArtifactsWorkflow Run: View Run Available Artifacts
How to DownloadOption 1: GitHub Web UI (easiest)
Option 2: GitHub CLI gh run download 38898859101 --repo smart-mcp-proxy/mcpproxy-go
|
Dumbris
added a commit
that referenced
this pull request
Oct 17, 2026
…nts (#1637) ## Root cause `TestConfigWatcher_ExternalRevertToLastSelfWriteReloads` flaked on macOS-15 runners (#1629, #1634). It is not a self-write-marker bug: with debug instrumentation under CPU load (reproduced ~1 in 100-250 runs locally on macOS), the final external revert to byte-identical A produced **no fsnotify event at all** after B's reload, so no debounce fired and the config stayed on B. fsnotify's kqueue backend can drop the event for a rename-over that follows a recently handled one. This is a real production hole (an external edit can be silently missed until restart), not only a test timing issue. ## Fix `runConfigWatchLoop` now also polls (2s) and compares file bytes with the last evaluated content; on a difference it arms the normal debounce -> `reloadFromDiskIfChanged` path, so self-write suppression is unchanged. The poll does not re-arm a pending debounce. ## Tests - New `TestConfigWatcher_PollRecoversMissedFsEvent` deterministically simulates total event loss (watch on an unrelated dir) and fails without the poll. - Before: 2 failures in ~120 runs, 1 in 250 (12 CPU spinners + 10 parallel test processes). After: 0 failures in 100 runs of the whole `TestConfigWatcher_` suite under the same load, plus 20 clean sequential `-race` runs. - golangci-lint (bare and `--build-tags server`) on `internal/runtime`: only a pre-existing `reflect.Ptr` inline finding in `event_bus.go`, untouched here.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two rug-pull bypasses in the tool-approval hash (
internal/runtime/tool_quarantine.go).#1606: colliding contracts. The v4 hash joined name, description and the normalized input schema with an unescaped
|. It appended the output schema only when one was present. SoA = (D, I, O)andB = (D|norm(I), O, none)got the same hash, and an approved A could switch to B and stay approved.storage.UnambiguousHashSchemaVersion, nowToolApprovalHashSchemaVersion). Every field is length-prefixed, with a domain tag. An absent output schema gets an explicitoutput:absentmarker. The safety-hint fingerprint is always encoded.calculateToolApprovalHashV4. It is used only for migration checks, and its existing goldens are now pinned against it.ApprovedHashcovers the stored contract (v4(stored) == ApprovedHash), and the stored contract equals the live one field by field. Anything else goes tochanged, through the normal path (scan evidence included intrust_mode: scan). This gate covers the formula migration, the content match and the serialization-only branches.v4PendingHashMatchesLive).legacySiblingApprovesContractnow uses the v4 formula that those records were written with.Previous*. A later pass therefore cannot "revert" to it.ApprovedHashis the hash of the recorded previous contract.hash_mismatchuntil re-pinned. This is existing behavior, now documented.#1591: added output schema treated as a formula migration. The fallback to the live output schema is already limited to records below
storage.OutputSchemaHashSchemaVersionon main (a857dba,uncaptured). This PR adds the cross-version regression test: a v4 record approved without an output schema, which then gains a poisoned one, stayschangedacross the v5 upgrade, in manual and scan trust modes.Docs:
docs/features/security-quarantine.mdcovers the v5 encoding, the upgrade rule and re-pinning.Test evidence
TestToolApprovalHash_CollidingContractIsHeldfailed on main (expected "changed", actual "approved"). It passes now.internal/runtime/tool_quarantine_hash_encoding_test.go: the unambiguous encoding, v5 goldens (cross-checked with an independent Python encoder), the v4 collision pin, an unchanged v4 record re-baselined (with and without output schema, and with non-default hints), a colliding v4 contract held (manual and scan), a v4 record whose hash does not cover its stored contract held, a v4 record that gains an output schema held (Tool approval: adding an outputSchema to an approved tool is accepted as a hash-formula migration (skips review and trust_mode=scan) #1591), and a v4 pending record that promotes when unchanged but not when colliding. I neutered the two new gates and confirmed the matching tests fail.gpt-6.1-sol. Round 1 raised 5 findings. Four were fixed (the unproven snapshot reused asPrevious*, the v4 sibling proof, the v3 sibling collision, and an empty-description v4 sibling being held for no reason), each with a regression test that fails on the prior commit. The fifth was kept as is:ApproveCurrentHashcopies a v4 hash before discovery, but the version follows the hash, so the next discovery applies the v4 proof gate. Sol agreed in round 2 that this is no bypass. Round 2 found one P2 (an empty-description v4 revert stayed held), now fixed with a test. Round 3: VERDICT: CLEAN.go test -race ./internal/runtime/passes on the final head.go test -race ./internal/storage/... ./internal/preflight/... ./internal/qapilot/... ./internal/httpapi/...andgo test -race -tags server -skip "<CI regex>" ./internal/server/...pass on the first commit. The follow-up commits touch onlyinternal/runtime.go run ./cmd/qapilot mutate --only M06,M07,M08(the mutations intool_quarantine.go): 3/3 detected, baseline passed.golangci-lintruns (bare and--build-tags server) oninternal/runtimeandinternal/storageare clean apart from one existinggovetinline note in the untouchedinternal/runtime/event_bus.go:1020.Closes #1606
Closes #1591