Skip to content

docs: fix inconsistent commandRegex example in policy engine - #19027

Merged
NTaylorMullen merged 1 commit into
mainfrom
ntm/fix-policy-doc-regex
Feb 13, 2026
Merged

docs: fix inconsistent commandRegex example in policy engine#19027
NTaylorMullen merged 1 commit into
mainfrom
ntm/fix-policy-doc-regex

Conversation

@NTaylorMullen

Copy link
Copy Markdown
Collaborator

Summary

Fix inconsistent commandRegex documentation and example. The example incorrectly used a ^ anchor which would never match because the pattern is tested against stringified JSON arguments.

Details

  • Updated docs/core/policy-engine.md to remove ^ from the commandRegex example.
  • Added a note explaining that commandRegex prepends \"command\":\" to the pattern.
  • Added a regression test in packages/core/src/policy/toml-loader.test.ts to verify that ^ in commandRegex causes a mismatch.

Related Issues

Fixes https://chat.google.com/room/AAQApBm33UQ/zJmZJPS5j1s/zJmZJPS5j1s?cls=10

How to Validate

  1. Run the new test: npm test -w @google/gemini-cli-core -- src/policy/toml-loader.test.ts
  2. Verify the test should NOT match if ^ is used in commandRegex because it matches against full JSON passes.
  3. Review the updated docs/core/policy-engine.md.

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • 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

- Remove incorrect `^` anchor from the `commandRegex` example in `policy-engine.md`.
- Clarify that `commandRegex` prepends `"command":"` to the pattern, effectively matching from the start of the command value.
- Add a regression test in `toml-loader.test.ts` to verify that `^` in `commandRegex` does not match the stringified JSON arguments.
@NTaylorMullen
NTaylorMullen requested review from a team as code owners February 13, 2026 19:50
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @NTaylorMullen, 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 addresses an inconsistency in the policy engine's commandRegex documentation and behavior. It clarifies how commandRegex patterns are evaluated against stringified JSON arguments, specifically highlighting why the ^ anchor can lead to unexpected mismatches. The changes improve the accuracy of the documentation and add a new test to prevent future regressions related to this specific regex behavior.

Highlights

  • Documentation Fixed: Corrected the commandRegex example in docs/core/policy-engine.md by removing an incorrect ^ anchor that would never match due to how the pattern is tested.
  • Clarity Added: Enhanced the commandRegex documentation with a note explaining that the pattern is tested against stringified JSON arguments, and that ^ should generally be avoided because it applies to the full JSON string, not just the command text.
  • Regression Test Implemented: Introduced a new test case in packages/core/src/policy/toml-loader.test.ts to ensure commandRegex correctly handles the ^ anchor when matching against full JSON strings, preventing future regressions.
Changelog
  • docs/core/policy-engine.md
    • Removed the ^ anchor from the commandRegex example.
    • Added a note explaining that commandRegex prepends "command":" to the pattern and that ^ should generally be avoided.
  • packages/core/src/policy/toml-loader.test.ts
    • Added a new test case to verify that ^ in commandRegex causes a mismatch when matching against the full JSON string.
Activity
  • The author has updated relevant documentation and added new tests.
  • Validation on MacOS using npm run has been completed.
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.

@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 clarifies the commandRegex documentation within the policy engine, correcting the understanding that the regex matches against the full JSON representation of arguments, and includes a regression test in toml-loader.test.ts. While these changes improve clarity and robustness, they also expose a critical architectural vulnerability. The policy engine's current method of matching commandRegex against a full JSON string of tool arguments allows for easy policy bypass through injection into non-validated fields, which could lead to unauthorized arbitrary command execution if an attacker can manipulate tool arguments. The remediation suggestion has been updated to reflect that toolCall.args must be parsed as a JSON string before accessing its properties.

Comment thread packages/core/src/policy/toml-loader.test.ts
@github-actions

Copy link
Copy Markdown

Size Change: -2 B (0%)

Total Size: 24.4 MB

ℹ️ View Unchanged
Filename Size Change
./bundle/gemini.js 24.4 MB -2 B (0%)
./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-open.sb 3.36 kB 0 B
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB 0 B
./bundle/sandbox-macos-strict-open.sb 4.82 kB 0 B
./bundle/sandbox-macos-strict-proxied.sb 5.02 kB 0 B

compressed-size-action

@NTaylorMullen
NTaylorMullen added this pull request to the merge queue Feb 13, 2026
Merged via the queue into main with commit c2f62b2 Feb 13, 2026
27 of 29 checks passed
@NTaylorMullen
NTaylorMullen deleted the ntm/fix-policy-doc-regex branch February 13, 2026 20:09
kuishou68 pushed a commit to iOfficeAI/gemini-cli-pro that referenced this pull request Feb 27, 2026
liamhelmer pushed a commit to badal-io/gemini-cli that referenced this pull request Mar 12, 2026
@sripasg sripasg added the size/s A small PR label Jun 2, 2026
software-0ficial pushed a commit to software-0ficial/gemini-cli that referenced this pull request Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/s A small PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants