Skip to content

chore(ci): fail on a shell or a dynamic eval outside tests #1363

Todo

Description

@chappie-daemon

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

  1. 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.
  2. 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 never format!-ed into the snippet.
  3. The same rule for dynamic evaluation: no eval(...) or new 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 on rewrite/main.
  • A bare eval\( grep in JS matches 11 hits, and every one is a Redis Lua eval method (cache.eval(...), plus two interface signatures), not dynamic code. Refined to exclude a preceding . it is 2 hits; new Function( is 0 and knex.raw does 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 main and rewrite/main once the existing two Redis-eval signatures 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/sh to 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.md or AGENTS.md on main.

Activity

  1. ItsAbir005 commented on Dec 3, 2026

    @ItsAbir005
    Contributor

    @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.

  2. cameri commented on Dec 3, 2026

    @cameri
    Owner

    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.

  3. ItsAbir005 commented on Dec 4, 2026

    @ItsAbir005
    Contributor

    Ok I have raise the PR pls check once

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions