deploy-gate icon indicating copy to clipboard operation
deploy-gate copied to clipboard

Bounty #36: reference receipt gate does not enforce signed inputHash (different action replay)

Open tmkmaj opened this issue 1 month ago • 2 comments

Claim for permission-protocol/deploy-gate#36.

Summary

The current reference receipt gate does not enforce the signed inputHash for the action it is authorizing. mcp-guard verify makes --call optional, and the shipped workflow never supplies it, so any action with the same expected scope, scope_ref, and scope_sha can reuse an otherwise valid human-approved receipt.

This is distinct from the already-fixed issues #60, #61, #64, and #65. The token/receipt signature is valid and the inputHash is correctly signed. The flaw is that the gate does not recompute and compare that hash against the action it is about to permit.

Exact locations

  • mcp-guard/src/verify-cli.ts:139-146 — --call is optional and only passed when supplied.
  • mcp-guard/src/receipt-verify.ts:209-214 — the signed inputHash is checked only inside if (opts.call).
  • mcp-guard/templates/github-actions/receipt-gate.yml:73-78 — the reference gate verifies only --scope and --scope-sha; it never passes --call.
  • mcp-guard/src/webhook.ts:66-71 — the PR merge scope omits repository identity; the signed inputHash is the only place the repository is bound.
  • mcp-guard/src/proxy.ts:117-122 — deploy scope omits authorization-relevant arguments other than env/ref/SHA.

The internal release path in src/release.ts does pass call and idemKey when it has the held action. The external CLI/reference-gate path does not.

Reproduction: approve one action, run another

A human approves a deploy call with force: false:

{"env":"production","sha":"a1b2c3d4","force":false}

The gate is then invoked exactly as the reference workflow does:

--scope deploy:production --scope-sha a1b2c3d4

The actual call is:

{"env":"production","sha":"a1b2c3d4","force":true}

Observed with current mcp-guard main (9193053):

normal human-approved action: {"env":"production","sha":"a1b2c3d4","force":false}
Receipt ... VERIFIED (jcs_v2, key pinned by --trust) for deploy:production @ a1b2c3d4. Gate green.
...
INPUT_HASH_MISMATCH: the signed inputHash is "sha256:9ce1daa8..." the call hashes to sha256:24e243e6...
gate without --call exit: 0
gate with malicious --call exit: 1

So the receipt authorizes force:false, but the documented gate path returns success for force:true.

Reproduction: cross-repository merge authorization

A receipt is issued for owner/repo-A, PR #7, head SHA a1b2c3d4, scoped as github:merge and refs/pull/7/merge. The same gate invocation for owner/repo-B with PR #7 and the same head SHA also returns success without --call:

approved repo: owner/repo-A
signed inputHash: sha256:81dcd192...
Receipt ... VERIFIED ... for github:merge refs/pull/7/merge @ a1b2c3d4. Gate green.
...
repo-B gate without --call exit: 0
repo-B gate with --call exit: 1 (INPUT_HASH_MISMATCH)

The repository identity is present in the signed inputHash, but it is never compared by the default gate. A Git commit object can be replicated across repositories, so the SHA check alone does not restore repository binding.

Impact

A valid human-approved receipt can be replayed for a different action within the same scope, or across repositories that share a signing key and scope tuple. The strongest form is cross-repository merge/deploy authorization. This directly violates the challenge's "replay an existing receipt against a different action" condition and the gate's stated "exact action" guarantee.

Suggested fix

  • Make the expected call mandatory for scoped receipt verification in verify-cli (or reject scoped verification when --call is absent).
  • Have the reference workflow require and supply the exact canonical call being authorized, rather than only --scope/--scope-sha.
  • Add a regression test that builds a human-approved scoped receipt, invokes the documented gate path without --call, and confirms it fails closed.

Validation

Reproduced locally against permission-protocol/mcp-guard main 9193053:

  • npm ci
  • npm run build
  • npm test (217 tests, 0 failures)
  • both PoCs above

The receipt signature itself remains valid; the bypass is in the gate's missing action binding. If this qualifies under #36, payment details can be provided privately.

tmkmaj avatar Oct 31 '26 04:10 tmkmaj

@rodchalski submitting this as a #36 bounty claim. The PoC is against current mcp-guard main and is distinct from the four previously accepted findings: the signature and signed inputHash are intact, but the documented reference gate never supplies --call, so it never compares the approved action to the action being authorized. The concrete outputs are in the issue body. If accepted, I can also open a focused hardening PR that makes scoped CLI verification require the exact call and adds regression coverage.

tmkmaj avatar Oct 31 '26 04:10 tmkmaj

Opened the hardening PR: permission-protocol/mcp-guard#19. It adds an opt-in --require-call and updates the reference workflow to require the exact call, so the signed inputHash is actually compared to the action being authorized.

tmkmaj avatar Oct 31 '26 04:10 tmkmaj