Repository navigation
Description
Why
The review of #1360 raised the general question: should a command ever be built from data? That diff is tests-only and safe — three /bin/sh -c call sites, all compile-time literals, one of which passes its argument after the snippet so it arrives as $1. But the class (a string becoming a command) deserves a standing rule rather than a review that has to notice it each time.
Rust already gives most of the invariant for free: Command::new(program).args([...]) never re-parses an argument, so data cannot become syntax. The property is only lost where a shell is involved.
Invariant
- Non-test code never invokes a shell. No
/bin/sh,/bin/bash,/usr/bin/env sh, and no-c. Programs are spawned as argv, so no argument can be reinterpreted as syntax. - Where a shell is genuinely required, the program text is a compile-time literal and values arrive as positional parameters (
$1, quoted"$@"). A value is neverformat!-ed into the snippet. - The same rule for dynamic evaluation: no
eval(...)ornew Function(...)on a variable in the JS tree, and no SQL built by interpolation — bindings or a literal only.
Check
Measured against the real trees before proposing this, which changed the shape twice:
Command::new("sh")is the wrong pattern in Rust: it is near-vacuous, because production spawns through a variable (Command::new(program)) and the tests reach the shell through a helper (argv("/bin/sh", ...)). It matches nothing onrewrite/main.- A bare
eval\(grep in JS matches 11 hits, and every one is a Redis Luaevalmethod (cache.eval(...), plus two interface signatures), not dynamic code. Refined to exclude a preceding.it is 2 hits;new Function(is 0 andknex.rawdoes not exist in the tree.
So the sinks are shell program paths, not spawn calls:
# Rust (crates/*/src/**/*.rs, both trees)
git grep -nE '"/bin/(ba)?sh"|"/usr/bin/(ba)?sh"|"/usr/bin/env"' -- 'crates/*/src/**/*.rs'
# JS (src/**/*.ts)
git grep -nE '(^|[^[:alnum:]_.])eval\(|new Function\(' -- 'src/**/*.ts'
A match fails the job unless the same line carries // shell-allowed: <reason> (or // eval-allowed: <reason>), and the reason is what review sees. The grep cannot tell an enclosing #[cfg(test)] from production, which is precisely why the marker — not a scope heuristic — is the mechanism: a deliberate use becomes a visible decision instead of an invisible convention.
Measured on the #1360 branch this check goes red on exactly the three test sites and green after their markers land, which makes that branch its own first test case.
Rejected: a syn-based walk (correct, but a parser dependency for a check a grep answers), clippy disallowed_methods (matches method paths, not string arguments), and a path allow-list (in-module test modules share a file with production code).
Where it runs
A step in .github/workflows/checks.yml next to the lint jobs, so it is a required context rather than advisory. Both trees: main is the JS relay, rewrite/main is the Rust one.
Acceptance
- The checker exits 0 on
mainandrewrite/mainonce the existing two Redis-evalsignatures and, after test(services): invoke /bin/sh directly in process tests (#1351) #1360, its three test sites carry markers. - It fails on a synthetic commit that adds
/bin/shto non-test code (shown on a throwaway branch, branch deleted after). - The invariant text lives where a contributor reads it: crate docs on
rewrite/main,deploy/README.mdorAGENTS.mdonmain.
Activity
ItsAbir005 commentedon Dec 3, 2026
@chappie-daemon @cameri I have the rewrite/main implementation ready on my fork (ItsAbir005/nostream, branch chore/shell-eval-guard, PR ItsAbir005#4) if I can be assigned to open the PR against rewrite/main.
cameri commentedon Dec 3, 2026
Let's please try and stick to the policy of requesting to be assigned before working on something or accept the risk your work may not get merged.
I will assign it to you this time.
ItsAbir005 commentedon Dec 4, 2026
Ok I have raise the PR pls check once