fix(core): prioritize conditional policy rules and harden Plan Mode#18882
fix(core): prioritize conditional policy rules and harden Plan Mode#18882Abhijit-2592 merged 2 commits intomainfrom
Conversation
Summary of ChangesHello @Abhijit-2592, 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 strengthens the PolicyEngine's security and predictability by enforcing explicit mode declarations for policy rules. It prevents policy rules from inadvertently affecting unintended operational modes and specifically hardens the Plan mode against arbitrary shell command execution, thereby reducing potential security risks. Highlights
Changelog
Activity
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. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request enhances the policy engine's security and clarity by requiring policy rules to explicitly declare modes for tool exclusion. This prevents rules from one mode accidentally affecting another. The changes are well-implemented in PolicyEngine.getExcludedTools and are accompanied by thorough updates to the test suite, including a new test case for the explicit mode requirement. Additionally, a specific security hardening has been added to plan.toml to explicitly deny run_shell_command in plan mode. The changes are logical and correctly implemented. I have reviewed the code and found no issues of high or critical severity.
|
Size Change: +133 B (0%) Total Size: 24.3 MB ℹ️ View Unchanged
|
e9e09ea to
ce58f73
Compare
Policy rules must now explicitly specify 'modes' to be considered by the PolicyEngine for excluding tools from the model. This prevents accidental exclusions from rules intended for different approval modes. Also explicitly denies 'run_shell_command' in Plan mode for enhanced security.
Ensure tools with argsPattern (conditional rules) are marked as processed so they aren't hidden by lower-priority global DENY rules. Fixes an issue in Plan Mode where conditional allows for write_file were being blocked by the global catch-all deny. Treat policy rules without explicit modes as applying to ALL modes (implicit default) for consistency and safety. Remove redundant explicit deny for run_shell_command in Plan Mode as the catch-all now correctly handles it.
ce58f73 to
2b50bfc
Compare

Summary
This PR ensures that conditional policy rules (using ) are correctly prioritized over global exclusion rules in the . This fixes a critical issue in Plan Mode where authorized tools (like for specific paths) were being blocked by the global catch-all deny. It also clarifies that policy rules without explicit apply to all modes by default for safety.
Details
Related Issues
Closes #18881
How to Validate
npm test -w @google/gemini-cli-core -- src/policy/policy-engine.test.tsPre-Merge Checklist