gemini-cli - ✅(Solved) Fix [Security] Improve dangerous command detection for rm and fix YOLO mode heuristics bypass [2 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
google-gemini/gemini-cli#25543Fetched 2026-04-17 08:55:26
View on GitHub
Comments
0
Participants
1
Timeline
6
Reactions
0
Participants
Assignees
Timeline (top)
cross-referenced ×2labeled ×2assigned ×1unlabeled ×1

The dangerous command detection for rm was found to be fragile, only catching specific flag combinations in the first argument position. This allowed path-qualified calls (e.g., /bin/rm) and split flags (e.g., rm -r -f) to bypass safety heuristics.

Root Cause

The dangerous command detection for rm was found to be fragile, only catching specific flag combinations in the first argument position. This allowed path-qualified calls (e.g., /bin/rm) and split flags (e.g., rm -r -f) to bypass safety heuristics.

Fix Action

Fixed

PR fix notes

PR #25544: security: improve dangerous command detection for rm and fix YOLO bypass

Description (problem / solution / changelog)

Summary

Improve dangerous command detection for rm, del, and erase to prevent accidental mass deletion. Fix a bug where shell heuristics were bypassed in YOLO mode.

Details

  • Robust rm Detection: Updated isDangerousCommand to correctly identify rm, del, and erase regardless of path qualification or flag ordering.
  • Inherently Dangerous Tools: These commands are now always flagged as dangerous unless they are help/version requests (--help, etc.).
  • YOLO Mode Safety Net: Fixed a bug in PolicyEngine.check to ensure shell heuristics are always applied in YOLO mode, preventing silent bypasses for dangerous commands.
  • UI Transparency: Updated confirmation labels to clearly state that permissions apply to the entire tool (e.g., "Allow all 'rm' commands for this session").

Related Issues

Closes #25543

How to Validate

  1. Run npm test -w @google/gemini-cli-core -- src/policy/policy-engine.test.ts to verify the new test cases.
  2. Manually test with rm test.txt in YOLO mode and verify it triggers a confirmation prompt.
  3. Verify that path-qualified calls like /bin/rm -rf are also caught.

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

Changed files

  • packages/cli/src/ui/components/messages/ToolConfirmationMessage.tsx (modified, +3/-2)
  • packages/cli/src/ui/components/messages/__snapshots__/ToolConfirmationMessage.test.tsx.snap (modified, +8/-8)
  • packages/core/src/policy/policy-engine.test.ts (modified, +11/-33)
  • packages/core/src/policy/policy-engine.ts (modified, +12/-20)
  • packages/core/src/sandbox/utils/commandSafety.test.ts (added, +81/-0)
  • packages/core/src/sandbox/utils/commandSafety.ts (modified, +13/-2)

PR #25545: security: improve dangerous command detection for rm

Description (problem / solution / changelog)

Summary

Improve dangerous command detection for rm to prevent accidental mass deletion.

Details

  • Robust rm Detection: Updated isDangerousCommand in POSIX environments to correctly identify rm regardless of path qualification (e.g., /bin/rm) or flag ordering.
  • Inherently Dangerous Tools: The rm command is now always flagged as dangerous, removing the fragile check that only looked for specific flags like -rf in the first argument position.
  • Platform Specificity: Maintained platform-specific checks (e.g., del and erase remain Windows-specific dangerous commands, and rm is correctly scoped to POSIX).

Related Issues

Closes #25543

How to Validate

  1. Run npm test -w @google/gemini-cli-core -- src/sandbox/utils/commandSafety.test.ts to verify the improved POSIX safety heuristics.
  2. Manually test with rm test.txt and verify it triggers a confirmation prompt.

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

Changed files

  • packages/core/src/sandbox/utils/commandSafety.test.ts (added, +91/-0)
  • packages/core/src/sandbox/utils/commandSafety.ts (modified, +3/-2)
  • packages/core/src/sandbox/windows/commandSafety.test.ts (modified, +6/-0)
  • packages/core/src/sandbox/windows/commandSafety.ts (modified, +2/-4)
RAW_BUFFERClick to expand / collapse

Description

The dangerous command detection for rm was found to be fragile, only catching specific flag combinations in the first argument position. This allowed path-qualified calls (e.g., /bin/rm) and split flags (e.g., rm -r -f) to bypass safety heuristics.

Improvements Made

  1. Robust rm Detection: Updated isDangerousCommand to correctly identify rm, del, and erase regardless of path qualification or flag ordering.
  2. Inherently Dangerous Tools: These commands are now always flagged as dangerous.
  3. UI Transparency: Updated confirmation labels to clearly state that permissions apply to the entire tool (e.g., "Allow all 'rm' commands for this session").

I have already implemented these fixes and verified them with new test cases.

extent analysis

TL;DR

The issue can be resolved by updating the isDangerousCommand function to correctly identify rm, del, and erase commands regardless of path qualification or flag ordering.

Guidance

  • Review the updated isDangerousCommand function to ensure it correctly handles various command formats, such as path-qualified calls and split flags.
  • Verify that the new test cases cover different scenarios, including edge cases like /bin/rm and rm -r -f.
  • Check the UI confirmation labels to ensure they clearly state the permissions scope for the entire tool.
  • Test the updated functionality with various command combinations to ensure the safety heuristics are working as expected.

Example

No code snippet is provided as the issue does not contain specific code details.

Notes

The provided information implies that the issue has already been fixed and verified with new test cases. However, it's still important to review and test the changes to ensure they work as expected in different scenarios.

Recommendation

Apply the workaround by using the updated isDangerousCommand function, as it provides more robust detection of dangerous commands.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING