Skip to content

fix(security): require approved bot patch artifacts#28178

Open
huynhtrungcsc wants to merge 1 commit into
google-gemini:mainfrom
huynhtrungcsc:fix/gemini-bot-approved-patch-artifact
Open

fix(security): require approved bot patch artifacts#28178
huynhtrungcsc wants to merge 1 commit into
google-gemini:mainfrom
huynhtrungcsc:fix/gemini-bot-approved-patch-artifact

Conversation

@huynhtrungcsc

Copy link
Copy Markdown

Summary

Require an explicit approval marker before the Gemini CLI bot publish job consumes bot-changes.patch.

This keeps the reasoning-to-publish boundary fail-closed: rejected critique runs now remove stale PR artifacts, and the publish job only applies a non-empty patch when it is paired with a marker generated after approval.

Testing

  • node ./node_modules/prettier/bin/prettier.cjs --check .github/workflows/gemini-cli-bot-brain.yml scripts/tests/gemini-cli-bot-brain-workflow.test.ts
  • node ./node_modules/eslint/bin/eslint.js scripts/tests/gemini-cli-bot-brain-workflow.test.ts
  • node ./node_modules/vitest/vitest.mjs run --config ./scripts/tests/vitest.config.ts scripts/tests/gemini-cli-bot-brain-workflow.test.ts --pool forks --poolOptions.forks.singleFork
  • node scripts/lint.js --actionlint

@huynhtrungcsc huynhtrungcsc requested review from a team as code owners June 27, 2026 19:15
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request implements a security gate for the Gemini CLI bot's patch publishing process. By requiring an explicit approval marker, the system ensures that only validated changes are consumed by the publish job. Additionally, the changes improve the reliability of the bot by ensuring that rejected critique runs clean up any stale artifacts, maintaining a secure and predictable state.

Highlights

  • Security Hardening: Introduced a mandatory approval marker requirement for the Gemini CLI bot to process patch artifacts, ensuring that only approved changes are published.
  • Artifact Lifecycle Management: Updated the workflow to automatically purge stale patch artifacts when critique results indicate a rejection, preventing accidental application of unapproved changes.
  • Verification: Added a comprehensive test suite to validate the workflow logic, ensuring that patch publishing is strictly gated by the approval marker.
Ignored Files
  • Ignored by pattern: .github/workflows/** (1)
    • .github/workflows/gemini-cli-bot-brain.yml
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions github-actions Bot added the size/m A medium sized PR label Jun 27, 2026
@github-actions

github-actions Bot commented Jun 27, 2026

Copy link
Copy Markdown

📊 PR Size: size/M

  • Lines changed: 116
  • Additions: +114
  • Deletions: -2
  • Files changed: 2

@google-cla

google-cla Bot commented Jun 27, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces a new test suite, gemini-cli-bot-brain-workflow.test.ts, to validate the behavior of the gemini-cli-bot-brain.yml GitHub workflow. The tests cover scenarios such as removing stale patch artifacts on rejection, creating publishable patch markers on approval, and verifying approval requirements. The feedback recommends normalizing CRLF line endings to LF when reading the workflow file to ensure the tests run reliably on Windows environments.

Comment on lines +19 to +22
const workflow = fs.readFileSync(workflowPath, 'utf8');
const match = workflow.match(
/^[ ]{6}- name: 'Generate Patch'[\s\S]*?^[ ]{8}run: \|\n([\s\S]*?)\n\n^[ ]{6}- name: 'Archive Brain Data'/m,
);

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.

high

The workflow file regex match and line splitting can fail on Windows environments if the repository is checked out with CRLF (\r\n) line endings. Normalizing the file content to use LF (\n) before matching ensures the test is robust and cross-platform.

Suggested change
const workflow = fs.readFileSync(workflowPath, 'utf8');
const match = workflow.match(
/^[ ]{6}- name: 'Generate Patch'[\s\S]*?^[ ]{8}run: \|\n([\s\S]*?)\n\n^[ ]{6}- name: 'Archive Brain Data'/m,
);
const workflow = fs.readFileSync(workflowPath, 'utf8').replace(/\r\n/g, '\n');
const match = workflow.match(
/^[ ]{6}- name: 'Generate Patch'[\s\S]*?^[ ]{8}run: \|\n([\s\S]*?)\n\n^[ ]{6}- name: 'Archive Brain Data'/m,
);

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Addressed in cfd0a59 by normalizing CRLF to LF before matching and extracting the workflow script. I also validated the CRLF extraction path locally.

@huynhtrungcsc huynhtrungcsc force-pushed the fix/gemini-bot-approved-patch-artifact branch 2 times, most recently from d24ea4c to 7251fdc Compare June 27, 2026 19:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/m A medium sized PR status/need-issue Pull requests that need to have an associated issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant