command-risk gate blocks routine read-only commands (2>/dev/null, grep -r, quoted heredocs) — fix attached
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 19.9k
- Forks
- 2.3k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 30
Description
The command-risk classifier refuses ordinary read-only shell commands, which is the failure mode the crate docs warn about: over-firing trains users to reflex-approve, and a gate that is always tripped protects nothing.
Four defects, all cascading from how redirects are parsed:
-
2>/dev/nulltokenizes the fd as a word and/dev/nullas a truncating redirect target./dev/nullsits under/dev, which is protected recursively, so the single most common shell idiom there is classified Catastrophic and cannot be run at all. -
Any redirect makes every operand a delete target, because the target list is built unconditionally.
grep -rn pat . > outreports.as a recursive delete and*.mdas an unknown-footprint glob. -
-ris read as "recursive delete" even when the program only reads, sogrep -randls -Rlook destructive. -
Quoted heredoc bodies are tokenized as code. A backtick or
$in documentation prose reads as command substitution, so writing a doc that merely mentions a path is blocked.
Fix: strip leading fds and >&N dups in the tokenizer; treat the discard sinks (/dev/null, /dev/zero, /dev/tty, stdout, stderr) as inert everywhere; only collect operands as targets when the program is actually destructive; require a destructive verb before -r counts as recursion; skip the bodies of quoted heredocs, which the shell itself does not expand.
Unquoted heredocs are still assessed, since the shell does expand those.
Reproduction
$ jcode run 'grep -rn TODO . 2>/dev/null'
refused as Catastrophic pre-fix (matches /dev/null under the protected /dev tree).
Fix
Patch attached (command_risk_fix.diff), scoped entirely to crates/jcode-command-risk/. It applies cleanly on current master (b80d9eb92) with no conflicts.
cargo test -p jcode-command-risk: 64 passed, 0 failed, including tests confirming rm -rf ~, device writes, out-of-cwd deletes, and clobbering redirects are all still gated.
Branch with the commit, if a maintainer would rather cherry-pick directly:
https://github.com/rameshbaskaran/jcode/tree/fix/command-risk-on-v66
(Repo settings restrict PR creation to collaborators, so filing this as an issue with a ready patch instead of a PR.)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in crates/jcode-command-risk/ and run cargo test -p jcode-command-risk to inspect the existing 64 tests and reproduce the grep command shown in the issue. Compare redirect, recursion, discard-sink, and heredoc behavior with the stated cases; done means routine read-only commands pass while destructive cases such as rm -rf ~ and device writes remain gated.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust, shell
- Domain
- cli, security
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100