Skip to content

fix(core): prioritize conditional policy rules and harden Plan Mode#18882

Merged
Abhijit-2592 merged 2 commits intomainfrom
abhijit-2592/plan-mode-excludes
Feb 12, 2026
Merged

fix(core): prioritize conditional policy rules and harden Plan Mode#18882
Abhijit-2592 merged 2 commits intomainfrom
abhijit-2592/plan-mode-excludes

Conversation

@Abhijit-2592
Copy link
Contributor

@Abhijit-2592 Abhijit-2592 commented Feb 12, 2026

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

  • Prioritize Conditional Rules: Updated to ensure that high-priority rules with are marked as processed. This prevents lower-priority global DENY rules (like the catch-all in Plan Mode) from overriding specific allowances.
  • Implicit Mode Inheritance: Rules without an explicit array now correctly apply to all modes. This prevents accidental security gaps where a general deny rule might be ignored in specific modes if not explicitly listed.
  • Plan Mode Verification: Verified that is correctly denied in Plan Mode by the global catch-all, while ensuring authorized file editing tools function as intended.
  • Cleanup: Removed redundant explicit deny rules in that are now safely covered by the improved engine logic.

Related Issues

Closes #18881

How to Validate

  1. Run core unit tests (including new Plan Mode simulation):
    npm test -w @google/gemini-cli-core -- src/policy/policy-engine.test.ts
  2. Run full preflight suite:
    npm run preflight

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (verified Plan Mode behavior)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

@Abhijit-2592 Abhijit-2592 requested a review from a team as a code owner February 12, 2026 06:51
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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

  • Explicit Mode Requirement for Policy Rules: Policy rules now require an explicit 'modes' array to be considered for tool exclusion, preventing unintended rule application across different approval modes.
  • Enhanced Plan Mode Security: The 'run_shell_command' tool is now explicitly denied in 'Plan' mode with a high priority, significantly enhancing security by preventing arbitrary shell command execution.
  • Expanded Test Coverage: Test coverage for the policy engine has been expanded to validate the new explicit mode requirement and existing tests have been updated to reflect this change.
Changelog
  • packages/core/src/policy/policies/plan.toml
    • Added a new policy rule to explicitly deny 'run_shell_command' in 'plan' mode with a priority of 100.
    • Updated comments to clarify the behavior of the catch-all deny rule.
  • packages/core/src/policy/policy-engine.test.ts
    • Introduced a new test case to verify that policy rules without an explicit 'modes' array are ignored.
    • Modified existing test cases within 'getExcludedTools' to include explicit 'modes' arrays for policy rules, aligning with the new requirement.
  • packages/core/src/policy/policy-engine.ts
    • Updated the 'getExcludedTools' method to skip any policy rule that does not define an explicit 'modes' array, ensuring rules are only applied when their intended modes are specified.
Activity
  • The author has marked the 'Added/updated tests' checklist item as complete.
  • The author has marked the 'Validated on required platforms/methods: MacOS (npm run)' checklist item as complete.
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 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 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

  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.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

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 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.

@github-actions
Copy link

github-actions bot commented Feb 12, 2026

Size Change: +133 B (0%)

Total Size: 24.3 MB

ℹ️ View Unchanged
Filename Size Change
./bundle/gemini.js 24.3 MB +133 B (0%)
./bundle/sandbox-macos-permissive-closed.sb 1.03 kB 0 B
./bundle/sandbox-macos-permissive-open.sb 890 B 0 B
./bundle/sandbox-macos-permissive-proxied.sb 1.31 kB 0 B
./bundle/sandbox-macos-restrictive-closed.sb 3.29 kB 0 B
./bundle/sandbox-macos-restrictive-open.sb 3.36 kB 0 B
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB 0 B

compressed-size-action

@gemini-cli gemini-cli bot added the area/enterprise Issues related to Telemetry, Policy, Quota / Licensing label Feb 12, 2026
@gemini-cli gemini-cli bot added the 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item. label Feb 12, 2026
@Abhijit-2592 Abhijit-2592 force-pushed the abhijit-2592/plan-mode-excludes branch from e9e09ea to ce58f73 Compare February 12, 2026 16:35
@Abhijit-2592 Abhijit-2592 changed the title feat(core): require explicit modes for policy tool exclusion fix(core): prioritize conditional policy rules and harden Plan Mode Feb 12, 2026
@Abhijit-2592
Copy link
Contributor Author

Abhijit-2592 commented Feb 12, 2026

This change ensures that the PLAN mode has the right set of tools as shown in the SC

Screenshot 2026-02-12 at 8 31 03 AM

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.
@Abhijit-2592 Abhijit-2592 force-pushed the abhijit-2592/plan-mode-excludes branch from ce58f73 to 2b50bfc Compare February 12, 2026 16:45
@Abhijit-2592 Abhijit-2592 added this pull request to the merge queue Feb 12, 2026
Merged via the queue into main with commit ddcfe5b Feb 12, 2026
27 checks passed
@Abhijit-2592 Abhijit-2592 deleted the abhijit-2592/plan-mode-excludes branch February 12, 2026 17:15
@jerop jerop mentioned this pull request Feb 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/enterprise Issues related to Telemetry, Policy, Quota / Licensing 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Tools] Fix write_tool getting excluded in Plan mode due to policy engine exclusions

2 participants