Skip to content

Deduplicate per-server allowlist membership checks - #17013

Merged
lpcox merged 2 commits into
mainfrom
copilot/duplicate-code-per-server-allowlist-checks
Nov 21, 2026
Merged

lpcox merged 2 commits into
mainfrom
copilot/duplicate-code-per-server-allowlist-checks

Conversation

@lpcox

@lpcox lpcox commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

isToolAllowed and isPromptAllowed duplicate the same lookup policy. This refactor centralizes that policy without changing enforcement or block logs.

  • Shared lookup: Add allowedByServerSet alongside the allowlist builders. Missing or nil sets allow all; non-nil sets use boolean membership, so empty sets deny all.
  • Callers: Retain independent tool and prompt maps and their existing log messages.
  • Regression coverage: Cover default behavior, empty sets, explicit false entries, and server/allowlist isolation.
allowed := allowedByServerSet(us.allowedToolSets, serverID, toolName)

@lpcox lpcox changed the title [WIP] Refactor duplicate code in allowlist membership checks Deduplicate per-server allowlist membership checks Nov 21, 2026
@lpcox
lpcox marked this pull request as ready for review November 21, 2026 16:50
Copilot AI adaptive review requested due to automatic review settings November 21, 2026 16:50
@github-actions

Copy link
Copy Markdown
Contributor

🔒 mcpg Read-Only Stress — default

Surface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Isolation runtime: default (normal container isolation)

Part Surface Op Result Expected Status
A MCP reads (list_issues/list_pull_requests/get_file_contents/list_commits) data returned ALLOWED ✅
B MCP writes (reaction/star/issue/comment/branch/file/PR) all 6 targets absent from gateway catalog (23 read-only tools only) BLOCKED ⚠️
C CLI reads (same 4 ops via proxied github CLI) data returned ALLOWED ✅
D CLI REST writes (reaction/star/issue/comment) gh not authenticated — untested BLOCKED ⚠️
E CLI GraphQL mutations (addReaction/addStar/createIssue) gh not authenticated — untested BLOCKED ⚠️

Overall: INCONCLUSIVE

⚠️ Part B: none of the 6 write tools (add_issue_comment, star_repository, issue_write, create_branch, create_or_update_file, create_pull_request) appear in the gateway's exposed tool catalog (only 23 read-only tools listed). This confirms backend read-only toolset configuration but cannot independently confirm the gateway's own DIFC/guard write-blocking layer, since no write call ever reached a write-capable backend.

⚠️ Parts D/E: gh auth status reports not authenticated in this environment ("not logged into any GitHub hosts"), so the token-scope write-boundary could not be exercised. No writes were attempted or leaked.

No writes leaked on any surface that was reachable; the inconclusive rows are coverage gaps, not failures.

🔒 mcpg read-only stress (default AWF runtime) by Read-Only Stress: default runtime

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

There are no active review issues for the change centralizing per-server allowlist checks.

No open issues 🎉

What changed in this PR

Centralizes per-server allowlist checks in MCP Gateway, addressing #16982 without changing tool or prompt enforcement or block logging.

Changes:

  • Adds a shared helper that allows missing or nil sets and checks boolean membership for non-nil sets.
  • Updates tool and prompt checks to use the helper while retaining separate allowlists and log messages.
  • Adds regression tests for default behavior, empty sets, false entries, and server/allowlist isolation.
File Description
internal/​server/​tool_registry_helpers.go Adds the shared allowlist lookup helper.
internal/​server/​prompt_call.go Delegates prompt checks to the helper.
internal/​server/​backend_call.go Delegates tool checks to the helper.
internal/​server/​allowed_sets_test.go Covers lookup semantics and allowlist isolation.

Review effort: Max (adaptive)

@lpcox
lpcox merged commit f28d7c9 into main Nov 21, 2026
38 checks passed
@lpcox
lpcox deleted the copilot/duplicate-code-per-server-allowlist-checks branch November 21, 2026 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[duplicate-code] Duplicate Code Pattern: Per-server allowlist membership checks

3 participants