[Bug] The execute_bash safety validator allows deleting the parent of the home directory
Description
The destructive-command guard fixed in #1951 blocks rm -rf ~ and rm -rf $HOME, but not their parent. These are still allowed:
rm -rf ~/.. ALLOWED
rm -rf ~/../.. ALLOWED
rm -rf $HOME/.. ALLOWED
rm -rf ${HOME}/.. ALLOWED
rm -rf "$HOME/.." ALLOWED
rm -rf /home/user/.. ALLOWED
rm -rf /Users/alice/.. ALLOWED
~/.. and $HOME/.. name the directory that holds every user's home (/home on Linux, /Users on macOS), and /home/user/.. is the same directory spelled out. Deleting it is at least as destructive as deleting ~ itself, which the validator already refuses.
This was raised by @addyCooks while reviewing #1951 and is intentionally out of scope there.
Environment
- OS: Windows 11
- Node version: v22.22.0
- Nanocoder version: 1.31.0 (main at 96c126e3, after #1951 merged)
- Provider: n/a — the validator is provider-independent
Steps to Reproduce
- Call the validator directly for each command:
executeBashTool.validator({command})(or runexecute_bashin yolo/headless mode, where no approval prompt stands in the way). - Observe
valid: truefor every variant above, whilerm -rf ~returnsvalid: false.
Expected Behavior
Blocked for the same reason rm -rf ~ and rm -rf / already are: a recursive force delete of the home directory's parent wipes every account.
Actual Behavior
Allowed. rm -rf ~ alone is blocked:
blocked rm -rf ~
ALLOWED rm -rf ~/..
ALLOWED rm -rf $HOME/..
ALLOWED rm -rf /home/user/..
Root cause
isDestructiveRmTarget in source/tools/execute-bash.tsx resolves .. by popping the previous segment and then compares the result against a fixed set (/, ~, $HOME, ${HOME}):
~/..pops~, leaving an empty relative path that is not in the set;$HOME/..and${HOME}/..do the same;/home/user/..resolves to/home, which is not a listed target either.
Suggested fix
Normalise ~, $HOME and ${HOME} to a synthetic home segment before resolving, then refuse a target whose resolved path is the home directory or its parent. That keeps rm -rf ~/project and rm -rf /home/user/project allowed while catching the variants above. Table-driven cases belong in source/tools/execute-bash.spec.tsx next to the existing ~/... block/allow lists.
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
@addyCooks — this is the follow-up you flagged while reviewing #1951. Opened with the repro and the root cause; if it looks right, could you assign it to me? I'd be happy to pick it up.
Thanks @Vishesh-Verma-07, confirmed against main: ~/.., ~/../.., $HOME/.. and ${HOME}/.. all pass the validator while rm -rf ~ is blocked. Assigning this to you.
Two things to cover in the PR:
- The /home/user/.. and /Users/alice/.. forms need the real home directory (os.homedir()), not just the ~ / $HOME normalisation.
rm -rf /homeandrm -rf /Usersare also allowed today. Please handle them in this PR or note them as a follow-up, keepingrm -rf ~/projectand ordinary paths like /tmp allowed.
Please add table-driven cases next to the existing ~/... block and allow lists in execute-bash.spec.tsx, plus a changeset.