Repository navigation
fix(security): bind /approve plan execution to verified comment and prune excess MCP tools - #540
Closed
elberthc-byte wants to merge 1 commit into
Closed
elberthc-byte wants to merge 1 commit into
elberthc-byte wants to merge 1 commit into
Conversation
…rune excess MCP tools - Verify @gemini-cli /approve comments deterministically in action.yml (scripts/resolve-approved-plan.mjs) before launching Gemini CLI with contents: write, requiring explicit comment ID/URL binding, verifying approver association and bot authorship, rejecting un-hashed edits and post-approval mutations, and writing .gemini/approved_plan.json. - Exclude mutable issue title/description from plan-execute context.json, migrate shipped .github/commands/gemini-{invoke,plan-execute}.toml from !{echo $VAR} shell interpolation to @{.gemini/...}, and configure .geminiignore + .git/info/exclude so AtFileProcessor reads .gemini/*.json. - Remove push_files, delete_file, fork_repository, issue_read, list_issues, and search_issues from plan-execute MCP includeTools (and prune existing @v0 .gemini/settings.json files automatically). - Add CI workflow, strict JS/TS typechecking, documentation updates, and 29 Vitest security/unit/integration tests.
Author
|
/gemini review |
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
Hardens the
@gemini-cli /approveplan-execution flow against Time-of-Check to Time-of-Use (TOCTOU) comment substitution, post-plan issue-body injection, shell-interpolation hazards, and over-privileged MCP tool grants:action.yml+scripts/resolve-approved-plan.mjs): Replaces LLM-driven"find a latest plan titled 'AI Assistant: Plan of Action'"comment lookup with a deterministic verification step inaction.ymlbeforegemini --yolostarts. Approval now requires binding to a specific plan comment ID or URL (@gemini-cli /approve <comment-url-or-id> [sha256:<prefix>]), verifies approver association (OWNER,MEMBER,COLLABORATOR), verifies plan authorship, rejects un-hashed pre-approval edits and all post-approval edits, fetches the target comment inGET /repos/{owner}/{repo}/issues/comments/{comment_id}), and writes a verified.gemini/approved_plan.jsonartifact (failing closed before Gemini CLI runs if any check fails).!{echo $...}Interpolation: Excludes mutabletitleanddescription(issue.body) from.gemini/context.jsonduringgemini-plan-execute(retaining routing fieldsevent_name,is_pull_request,issue_number, andrepositoryonly), migrates shipped.github/commands/gemini-{invoke,plan-execute}.tomltemplates from!{echo $...}shell execution to@{.gemini/context.json}/@{.gemini/approved_plan.json}, and updates.geminiignore(plus.git/info/excludewhen untracked) so.gitignore's.gemini/entry does not cause Gemini CLI'sAtFileProcessorto skip.gemini/*.jsonartifacts.push_files,delete_file,fork_repository,issue_read,list_issues, andsearch_issuesfrommcpServers.github.includeToolsingemini-plan-execute.yml(both.github/workflows/andexamples/workflows/), and automatically prunes those tools from.gemini/settings.jsonat action runtime so existing@v0consumers receive least-privilege enforcement automatically.Implementation Details
scripts/resolve-approved-plan.mjs,scripts/resolve-approved-plan.d.mts,action.yml):action.ymldeletes any pre-existing.gemini/approved_plan.jsonprior to runningresolve-approved-plan.mjs --verifyand verifies[[ -s ".gemini/approved_plan.json" ]]afterward, resolving symlinks viarealpathSyncinisExecutedAsMainScript()so macOS (/var->/private/var) and symlinked self-hosted runners never skip verification.event.action(createdforissue_commentandpull_request_review_comment,submittedforpull_request_review), verifiessender.type === 'User'andauthor_associationin['OWNER', 'MEMBER', 'COLLABORATOR'], detects PR conversation comments viaevent.issue.pull_request, rejects duplicate/malformed binding tokens, and verifies full comment URLs match the current<owner>/<repo>and issue/PR number.@v0Compatibility: EnforcesEXPECTED_PLAN_AUTHOR(<app-slug>[bot]when minted viaactions/create-github-app-token, orgithub-actions[bot]). WhenEXPECTED_PLAN_AUTHORis unset (existing@v0workflows), probesGET /userfor custom PATs and accepts repository-installed GitHub App bots (user.type === 'Bot',login.endsWith('[bot]'), andperformed_via_github_apppresent) while rejecting externalUsercommenters.@gemini-cli /approvewithout a target comment ID/URL; rejects comments withid >= approvalId(onissue_comment) or timestamps after approval; rejects plans edited in-place prior to approval (updated_at !== created_at) unless the approver explicitly pinssha256:<prefix>(CRLF-normalized, printing the 12-char digest hint in logs); and verifiescomment.issue_urlmatches the target repository and issue number..geminipaths or path traversal outside the workspace root (lstatSync+realpathSync), appends the ordered.geminiignorenegation stanza at EOF, and adds/.geminiignoreto.git/info/excludewhen untracked sogit add .workflows never stage.geminiignore..github/commands/gemini-{invoke,plan-execute}.tomland.github/workflows/gemini-{invoke,plan-execute}.ymlwithexamples/workflows/gemini-assistant/andexamples/workflows/gemini-dispatch/gemini-dispatch.yml.evals/gemini-assistant.eval.ts,evals/gemini-plan-execute.eval.ts, andevals/data/gemini-plan-execute.jsonfor.gemini/context.jsonand.gemini/approved_plan.json..github/workflows/ci.yml(permissions: contents: 'read', SHA-pinned actions) and wirednpm testtoevals/vitest.security.config.ts(pool: 'forks'), plusallowJs/checkJsstrict typechecking intsconfig.json.examples/workflows/gemini-assistant/README.md,examples/workflows/gemini-dispatch/README.md, andexamples/workflows/CONFIGURATION.md.Breaking Changes & Compatibility
/approve: Bare@gemini-cli /approvewithout a comment URL or ID now fails closed with an actionable error message instructing maintainers to reply with@gemini-cli /approve <comment-url-or-id>.gemini-invoke.tomlhas been updated to print this exact instruction in new plan comments.@v0Workflows: Existing consumers pinned togoogle-github-actions/run-gemini-cli@v0remain compatible acrossgithub.token, Custom GitHub Apps (vars.APP_ID), and custom PATs (secrets.GITHUB_TOKEN) without requiring immediate workflow YAML re-copying, and automatically receive.gemini/context.jsonand.gemini/settings.jsonsanitization.Verification
1. Automated Unit, Integration, & Linter Checks
npm test,pool: 'forks'):29 passed (29)inevals/gemini-plan-execute.security.test.tscovering static YAML/TOML security invariants,generate-examples.shparity, directive/URL/SHA-256 parsing, PR review vs. issue comment ID namespaces, TOCTOU race and edit rejection, cross-repo/cross-issue URL spoofing, symlinked action runner execution,.gemini/settings.jsontool pruning,.geminiignoreordering +.git/info/exclude, and live local HTTP server subprocess execution.tsc --allowJs --checkJs --strict --noEmit),eslint --max-warnings 0,actionlint,shellcheck --enable=all,yamllint,prettier --check, andnpm run build.2. End-to-End Manual Shell & HTTP Verification Matrix
Executed the composite action bash pipeline (
Prepare prompt context->Install Custom Commands->Verify approved plan) against a local HTTP GitHub API mock server across temporary git workspaces containing.gitignore(.gemini/):.gitignore/.geminiignore#100(created_at == updated_at),OWNERposts@gemini-cli /approve ...#issuecomment-100exit 0; writes.gemini/approved_plan.json, stripstitle/descriptionfrom.gemini/context.json, prunes disallowed MCP tools from.gemini/settings.json, un-ignores context/plan files@gemini-cli /approve(no comment ID/URL)#100exists,OWNERposts bare@gemini-cli /approveexit 1(fail-closed; rejects unbound latest-comment selection)[T_read, T_approve]race (newer comment before/approve)#100(18:00Z), newer comment#150(18:04Z) beforeMEMBERposts/approve #issuecomment-100(18:10Z)exit 0; binds strictly to#100viaUserposts#150,OWNERposts/approve 150exit 1(author "public-user" is not an authorized plan bot)sha256:pin#100(created_at: 18:00Z,updated_at: 18:03Z),OWNERposts/approve 100exit 1(printssha256:<12-char>digest hint for inspection)sha256:pinCOLLABORATORposts/approve 100 sha256:<matching-prefix>exit 0(explicitly authorized digest verified)updated_at > approvalTimestamp)#100edited at18:11Zafter18:10Z/approve, even with hashexit 1(created or modified after approval)CONTRIBUTOR) / edited webhook actionCONTRIBUTORposts/approve 100orissue_comment.editedeventexit 1(rejected before LLM execution)GITHUB_ACTION_PATH(macOS/var->/private/var)exit 0& writes artifact; invalid ->exit 1(never fails open)Checklist
action.ymland workflow YAML manifests (actionlint,yamllint).github/andexamples/workflows/templatesnpm test)examples/workflows/gemini-assistant/README.md,examples/workflows/gemini-dispatch/README.md,examples/workflows/CONFIGURATION.md)