nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Bug] execute_bash refuses harmless commands that only mention "rm -rf /" inside quotes or an echo

Open addyCooks opened this issue 2 weeks ago • 1 comments

Description

PR #2090 stopped the pattern guard from refusing quoted text such as grep "dd if=" build.log. The separate rm check still looks at quoted and echoed text, so a commit message or a note that mentions rm -rf / is refused as "potentially destructive", in every mode.

Environment

  • OS: Windows 11 Home 10.0.26300
  • Node version: v22.22.3
  • Nanocoder version: 1.32.0 (built from main at 5df35b3a)
  • Provider: Not provider-specific
  • Model: Not model-specific

Steps to Reproduce

  1. Call executeBashTool.validator with each of these commands:
    • git commit -m "docs: warn never to run rm -rf / on CI"
    • echo 'rm -rf ~' >> notes.txt
    • grep -rn "rm -rf /" scripts/

Expected Behavior

All three are allowed. They only print or write text.

Actual Behavior

All three are refused.

Logs/Screenshots

REFUSED <- git commit -m "docs: warn never to run rm -rf / on CI"
REFUSED <- echo 'rm -rf ~' >> notes.txt
REFUSED <- grep -rn "rm -rf /" scripts/
ALLOWED <- git commit -m "docs: explain why chmod -R 000 is blocked"   (fixed by #2090)

Command contains potentially destructive operation: "git commit -m ...". This command is blocked for safety.

Additional Context

  • [x] I have searched existing issues to ensure this is not a duplicate
  • [x] I can reproduce this issue consistently
  • [x] This issue occurs with the latest version of nanocoder (main)

Suggested fix:

  • source/tools/execute-bash.tsx:229 (rmArgumentLists) and :371-374: only treat an rm that is actually in command position as a command. Reuse the quoted-span blanking that PR #2090 added for the pattern list, with the same exceptions (a span in command position, after a redirect, or handed to another shell).
  • Add tests for the three commands above, and keep tests that a real rm -rf / is still refused.

Related: #1938, PR #2090, #1990 and PR #2000 (same guard).

addyCooks avatar Nov 16 '26 09:11 addyCooks

I'm picking this up. Plan: treat an rm as a command only when it is in command position, reusing the quoted-span blanking from #2090 with the same exceptions, and add tests for the three commands above alongside tests that a real rm -rf / (and rm -rf ~) is still refused.

PloneMraz avatar Nov 17 '26 03:11 PloneMraz