fix: enforce project_ref scope on destructive branch tools - #351
Open
mansueli wants to merge 1 commit into
Open
Conversation
When the MCP server is configured with projectId / project_ref, create_branch and list_branches already inject that project, but delete_branch, merge_branch, reset_branch, and rebase_branch accepted any branch_id and forwarded it to the Management API without checking parent_project_ref. Before mutating, resolve the scoped project's branches and require the target branch id (or project_ref) to belong to that project. Unscoped servers keep org-wide behavior. Adds regression tests for cross-project rejection and same-project delete.
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
When the MCP server is scoped with
project_ref/projectId,create_branchandlist_branchesalready inject that project ID. Destructive branch tools (delete_branch,merge_branch,reset_branch,rebase_branch) only accepted a caller-controlledbranch_idand forwarded it to the Management API with no check that the branch’sparent_project_refmatched the scoped project.That breaks the documented project-scoping guarantee: a client scoped to Project A could mutate a development branch belonging to Project B if both were covered by the same org OAuth grant and the caller knew the foreign
branch_id.Fix
Before any destructive branch mutation, if the server is project-scoped:
branch_idmatches a branchidorproject_refunder that projectUnscoped servers keep existing org-wide behavior.
Test plan
branch_idfor delete/merge/reset/rebase and does not delete the foreign branchcreate/list/merge/reset/rebase/ read-only)Notes
GET /v1/branches/{branch_id_or_ref}returnsBranchDetailResponsewithoutparent_project_ref, so ownership is validated via the project’s branch list (same filter aslist_branches).