fix(core): fail closed in YOLO mode when shell parsing fails for restricted rules#25935
fix(core): fail closed in YOLO mode when shell parsing fails for restricted rules#25935
Conversation
|
Hi @ehedlund, thank you so much for your contribution to Gemini CLI! We really appreciate the time and effort you've put into this. We're making some updates to our contribution process to improve how we track and review changes. Please take a moment to review our recent discussion post: Improving Our Contribution Process & Introducing New Guidelines. Key Update: Starting January 26, 2026, the Gemini CLI project will require all pull requests to be associated with an existing issue. Any pull requests not linked to an issue by that date will be automatically closed. Thank you for your understanding and for being a part of our community! |
|
Size Change: +253 B (0%) Total Size: 33.7 MB
ℹ️ View Unchanged
|
Summary of ChangesHello, 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 resolves a critical security vulnerability in the policy engine's YOLO mode. Previously, if shell command parsing failed for rules with argument patterns, the system would incorrectly default to allowing the command, creating a bypass. The changes ensure that such commands are now explicitly denied, thereby strengthening the security posture by implementing a 'fail closed' mechanism when argument validation cannot be reliably performed. Highlights
Using Gemini Code AssistThe 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
Customization To customize 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 Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. 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
|
There was a problem hiding this comment.
Code Review
This pull request enhances the PolicyEngine to fail closed in YOLO mode when shell command parsing fails or encounters syntax errors for rules with argument restrictions. It also adds unit tests for these scenarios. The review feedback suggests extending the fail-closed logic to include rules with commandPrefix restrictions and recommends using mockImplementationOnce or try...finally blocks in tests to prevent mock state leakage and ensure test isolation.
Summary
Fixes an issue where
run_shell_commandcalls with restricted rules (rules that only allow a tool if its arguments match a specific pattern) could be incorrectly allowed in YOLO mode if the shell command parser failed or encountered syntax errors.Details
In YOLO mode, the policy engine previously defaulted to
ALLOWif no subcommands were found, assuming the command was simple and matched the top-level rule. However, if a rule has anargsPattern, it implies that specific arguments must be validated. If the parser fails to identify subcommands (or has errors), we cannot reliably validate those arguments. This change ensures we "fail closed" in these cases for restricted rules.Before:
After:
Related Issues
None.
How to Validate
Run the unit tests for the policy engine:
npm test -w @google/gemini-cli-core -- src/policy/policy-engine.test.tsPre-Merge Checklist