Skip to content

security: improve dangerous command detection for rm#25545

Open
cocosheng-g wants to merge 1 commit intomainfrom
fix/rm-safety
Open

security: improve dangerous command detection for rm#25545
cocosheng-g wants to merge 1 commit intomainfrom
fix/rm-safety

Conversation

@cocosheng-g
Copy link
Copy Markdown
Contributor

@cocosheng-g cocosheng-g commented Apr 16, 2026

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

@cocosheng-g cocosheng-g requested a review from a team as a code owner April 16, 2026 17:08
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 security posture of the CLI by improving the detection of potentially destructive shell commands and ensuring that safety heuristics cannot be bypassed in YOLO mode. These changes prevent accidental mass deletions and provide clearer feedback to users when approving tool execution.

Highlights

  • Enhanced Dangerous Command Detection: Improved detection for 'rm', 'del', and 'erase' commands to be more robust against path qualification and flag ordering, ensuring they are flagged as dangerous unless they are help/version requests.
  • YOLO Mode Safety Fix: Corrected a bug in the PolicyEngine that allowed dangerous commands to bypass shell heuristics when running in YOLO mode, ensuring safety checks are now consistently applied.
  • UI Transparency: Updated confirmation messages to clearly indicate that permissions apply to the entire tool for the current session.
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.

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.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 16, 2026

Size Change: -99 B (0%)

Total Size: 33.6 MB

Filename Size Change
./bundle/chunk-B4ZHRZIJ.js 0 B -3.8 kB (removed) 🏆
./bundle/chunk-H6CYASTD.js 0 B -3.43 MB (removed) 🏆
./bundle/chunk-HA6367YL.js 0 B -14.5 MB (removed) 🏆
./bundle/core-7A6JUEEV.js 0 B -46.7 kB (removed) 🏆
./bundle/devtoolsService-EW7GFBVS.js 0 B -28.4 kB (removed) 🏆
./bundle/gemini-ZHRKSWKT.js 0 B -553 kB (removed) 🏆
./bundle/interactiveCli-EGAYNZZX.js 0 B -1.29 MB (removed) 🏆
./bundle/oauth2-provider-BPIBGFXK.js 0 B -9.16 kB (removed) 🏆
./bundle/chunk-6NWSY62P.js 14.5 MB +14.5 MB (new file) 🆕
./bundle/chunk-CL6AO2NW.js 3.8 kB +3.8 kB (new file) 🆕
./bundle/chunk-SAOS2CVK.js 3.43 MB +3.43 MB (new file) 🆕
./bundle/core-XUD3FLDJ.js 46.7 kB +46.7 kB (new file) 🆕
./bundle/devtoolsService-R5WVRDGU.js 28.4 kB +28.4 kB (new file) 🆕
./bundle/gemini-LZJHERM2.js 553 kB +553 kB (new file) 🆕
./bundle/interactiveCli-KQBF3A3F.js 1.29 MB +1.29 MB (new file) 🆕
./bundle/oauth2-provider-BV3MYH5B.js 9.16 kB +9.16 kB (new file) 🆕
ℹ️ View Unchanged
Filename Size Change
./bundle/bundled/third_party/index.js 8 MB 0 B
./bundle/chunk-34MYV7JD.js 2.45 kB 0 B
./bundle/chunk-5AUYMPVF.js 858 B 0 B
./bundle/chunk-5PS3AYFU.js 1.18 kB 0 B
./bundle/chunk-664ZODQF.js 124 kB 0 B
./bundle/chunk-DAHVX5MI.js 206 kB 0 B
./bundle/chunk-IUUIT4SU.js 56.5 kB 0 B
./bundle/chunk-LV2OUWFA.js 1.97 MB 0 B
./bundle/chunk-RJTRUG2J.js 39.8 kB 0 B
./bundle/cleanup-IX5GZ2QQ.js 0 B -932 B (removed) 🏆
./bundle/devtools-36NN55EP.js 696 kB 0 B
./bundle/dist-T73EYRDX.js 356 B 0 B
./bundle/events-XB7DADIJ.js 418 B 0 B
./bundle/examples/hooks/scripts/on-start.js 188 B 0 B
./bundle/examples/mcp-server/example.js 1.43 kB 0 B
./bundle/gemini.js 4.97 kB 0 B
./bundle/getMachineId-bsd-TXG52NKR.js 1.55 kB 0 B
./bundle/getMachineId-darwin-7OE4DDZ6.js 1.55 kB 0 B
./bundle/getMachineId-linux-SHIFKOOX.js 1.34 kB 0 B
./bundle/getMachineId-unsupported-5U5DOEYY.js 1.06 kB 0 B
./bundle/getMachineId-win-6KLLGOI4.js 1.72 kB 0 B
./bundle/memoryDiscovery-CMNXJICE.js 980 B 0 B
./bundle/multipart-parser-KPBZEGQU.js 11.7 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/client/main.js 222 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/_client-assets.js 229 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/index.js 13.4 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/types.js 132 B 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-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
./bundle/src-QVCVGIUX.js 47 kB 0 B
./bundle/tree-sitter-7U6MW5PS.js 274 kB 0 B
./bundle/tree-sitter-bash-34ZGLXVX.js 1.84 MB 0 B
./bundle/cleanup-XWJZR72E.js 932 B +932 B (new file) 🆕

compressed-size-action

gemini-code-assist[bot]

This comment was marked as outdated.

@cocosheng-g cocosheng-g force-pushed the fix/rm-safety branch 2 times, most recently from 377a015 to 16748e1 Compare April 16, 2026 17:18
@cocosheng-g cocosheng-g changed the title security: improve dangerous command detection for rm and fix YOLO bypass security: improve rm detection and clarify UI labels Apr 16, 2026
@cocosheng-g cocosheng-g force-pushed the fix/rm-safety branch 4 times, most recently from 11b6bcf to 738fd27 Compare April 16, 2026 17:28
@gemini-cli gemini-cli bot added the area/security Issues related to security label Apr 16, 2026
@cocosheng-g cocosheng-g force-pushed the fix/rm-safety branch 5 times, most recently from f3173fc to 9f17bbe Compare April 16, 2026 18:15
@cocosheng-g cocosheng-g changed the title security: improve rm detection and clarify UI labels security: improve dangerous command detection for rm Apr 16, 2026
@cocosheng-g
Copy link
Copy Markdown
Contributor Author

/gemini review

Copy link
Copy Markdown
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 improves command safety by utilizing normalizeCommand in both POSIX and Windows implementations and expanding the detection of the rm command. New tests have been added to verify these improvements. The review identifies potential security bypasses, specifically regarding how sudo flags are handled in POSIX and the lack of coverage for certain file extensions and aliases on Windows.

}

const cmd = args[0];
const cmd = normalizeCommand(args[0]);
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.

security-high high

The isDangerousCommand function is vulnerable to bypass when sudo is used with flags (e.g., sudo -u root rm). The recursive call isDangerousCommand(args.slice(1)) in the sudo block (lines 438-440) incorrectly processes the arguments, causing normalizeCommand to check a flag like -u instead of the actual dangerous command. This allows dangerous commands to be executed without detection, circumventing safety logic like YOLO mode overrides or user prompts.

References
  1. Correct identification of dangerous commands is essential for the system to apply safety policies, such as YOLO mode's 'ALLOW' decision or the default 'ASK_USER' prompt.

if (cmd.endsWith('.exe')) {
cmd = cmd.slice(0, -4);
}
const cmd = normalizeCommand(args[0]);
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.

security-high high

The isDangerousCommand function on Windows has multiple bypass vulnerabilities. Firstly, normalizeCommand does not account for trailing dots or other executable extensions (like .bat, .cmd). This allows an attacker to bypass dangerous command detection by appending a dot to a dangerous command name (e.g., powershell. resolves to powershell.exe). Secondly, the common PowerShell alias rm for Remove-Item is not explicitly flagged as dangerous, creating a security gap. Both issues allow dangerous commands to be executed without detection, preventing the system from correctly applying safety policies.

Suggested change
const cmd = normalizeCommand(args[0]);
const cmd = normalizeCommand(args[0]);
if (cmd === 'rm') return true;
References
  1. Correct identification of dangerous commands is essential for the system to apply safety policies, such as YOLO mode's 'ALLOW' decision or the default 'ASK_USER' prompt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/security Issues related to security

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Security] Improve dangerous command detection for rm and fix YOLO mode heuristics bypass

1 participant