Skip to content

fix(security): bind /approve plan execution to verified comment and prune excess MCP tools - #541

Merged
DavidAPierce merged 7 commits into
google-github-actions:mainfrom
elberthc-byte:b-584422505-run
Nov 19, 2026
Merged

DavidAPierce merged 7 commits into
google-github-actions:mainfrom
elberthc-byte:b-584422505-run

Conversation

@elberthc-byte

@elberthc-byte elberthc-byte commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Hardens the @gemini-cli /approve plan-execution flow against Time-of-Check to Time-of-Use (TOCTOU) comment substitution, post-plan issue-body injection, and over-privileged MCP tool grants:

  1. Deterministic Pre-Execution Plan Verification (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 in action.yml before gemini --yolo starts. Approval now requires binding to a specific plan comment ID or URL (@gemini-cli /approve <comment-url-or-id>), verifies approver association (OWNER, MEMBER, COLLABORATOR), verifies bot authorship (EXPECTED_PLAN_AUTHOR with @v0 App/PAT fallback), rejects edited comments and post-approval comments, fetches the target comment directly (GET /repos/{owner}/{repo}/issues/comments/{comment_id}), verifies comment.issue_url, and writes .gemini/approved_plan.json (failing closed before Gemini CLI runs if any check fails).
  2. Eliminate Post-Plan Issue-Body (DESCRIPTION) Injection: Excludes mutable title and description (issue.body) from .gemini/context.json during gemini-plan-execute (retaining routing fields event_name, is_pull_request, issue_number, and repository only), migrates shipped .github/commands/gemini-{invoke,plan-execute}.toml templates from !{echo $...} shell expansion to @{.gemini/context.json} / @{.gemini/approved_plan.json}, and updates .geminiignore so .gitignore entries for .gemini/ do not hide those files from Gemini CLI.
  3. Least-Privilege MCP Tool Allowlist: Removes push_files, delete_file, fork_repository, issue_read, list_issues, and search_issues from mcpServers.github.includeTools in gemini-plan-execute.yml (both .github/workflows/ and examples/workflows/), and automatically prunes those tools (plus merge_pull_request and dotted issue_read.*, populating excludeTools) from .gemini/settings.json at action runtime for existing @v0 consumers.

Verification

  • Validated workflow and action YAML manifests (actionlint, yamllint, zizmor, ratchet, shellcheck)
  • Synchronized .github/ and examples/workflows/gemini-assistant/ templates
  • Added 22 unit and local HTTP end-to-end security tests (npm test in .github/workflows/ci.yml), isolated from ambient GitHub Actions runner environment variables
  • Updated assistant documentation (examples/workflows/gemini-assistant/README.md)
  • Formatted all touched files with Prettier

…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 templates from !{echo $...} shell interpolation to @{.gemini/...}, and configure .geminiignore and .git/info/exclude safely.
- Remove push_files, delete_file, fork_repository, issue_read, list_issues, and search_issues from plan-execute MCP includeTools and automatically prune them from .gemini/settings.json for @v0 consumers.
- Pin action references to commit hashes in modified workflows, synchronize examples via generate-examples.sh, and add 29 Vitest security tests plus .github/workflows/ci.yml.
…pat, and symlink checks

- Use local './' action with default_branch checkout in self-hosted gemini-{invoke,plan-execute}.yml and update generate-examples.sh so post-merge runs use the repo's own action.yml without checking out untrusted fork PR trees on review events.
- Synthesize .gemini/context.json from legacy env vars in prepareContextAndGeminiIgnore for existing @v0 gemini-invoke consumers.
- Harden segment-by-segment/dangling symlink checks, git worktree info/exclude support, fail-closed comment.issue_url and dot-segment slug checks, excludeTools fallback (including merge_pull_request), Vitest v4 maxWorkers config, and add unit/E2E tests.

@bdmorgan bdmorgan left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM

@DavidAPierce
DavidAPierce merged commit c8bfcfc into google-github-actions:main Nov 19, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants