Issue #2723: Build ADR-raw-sinks-1 D19: a shell or interpreter named as the program of process::run is a raw sink

Open and answer this issue on GitHub.

blocked, safety · opened 2026-11-22 · updated 2026-11-22 · 7 comments

Builds D19 of ADR-raw-sinks-1, the owner’s decision on “Decision: a shell named as the program of process::run (sh -c, cmd /c) is a shell sink” (#2717), alternative B.

Problem

let name = req.query("file") ?? ""
process::run("sh", ["-c", f"convert {name} thumb.png"])   // name = "x; rm -rf ~"

This builds and runs the stranger’s text as shell code.

To build

  1. One list in std (Nikaia, beside raw_sinks.nika).
    • Shells: sh, bash, zsh, dash, ksh, fish, cmd, powershell, pwsh.
    • Interpreters: python, python3, perl, ruby, node, ssh.
    • Runners: env, sudo, nohup, timeout, nice, xargs.
    • Match on the base name; ignore .exe and case on Windows.
  2. The prover. When the literal program, or each literal of a D10 match, is on the list, every element of args with an outside part is refused, NK1308, unless untrusted-shell is allowed (D4, D5).
    • No predicate clears it.
    • A runner passes the check on to its first operand: the first element not starting with -, and after the number for timeout and nice.
    • That operand is checked as a program under D10.
  3. The run-time check under raw-sinks = "warn" (D7) throws io::IoError::Other, naming the program and the argument.
  4. The help for NK1308 / untrusted-shell names the list and says to run the commands with process::run one by one instead.
  5. Tests in tests/compiler/tests/, each with its .stdout/.stderr:
    • refused: sh -c with outside text;
    • refused: /bin/bash;
    • refused: env sh -c;
    • refused: python3 -c;
    • refused: sh -ec;
    • passes: sh -c with a fully literal text;
    • passes: with the key allowed.
  6. Our own calls are proved, not allowed. scripts/ and benches/ have many process::run("sh", ["-c", …]) calls (ledgers.nika, analysis_cost.nika, solver.nika, lower_mine.nika, the benches’ run helpers, release.nika/pre-push.nika via python3).
    • Every call whose text has an outside part is rewritten without a shell: one process::run per command, a pipe as two runs, a glob through fs.
    • No untrusted-shell allow and no trusted: goes into our manifests.
    • A form that cannot yet be written without a shell (e.g. a pipe between two processes) stops the work: Result: blocked, with the gap named.
  7. Docs. Part III 17 (std::process) and 13.3 (untrusted-shell), and website/safe, state the rule.

Done when

Comments

keywan-ghadami, 2026-11-22

Brief queued: issue-2723


agent: builder model: opus max_turns: 200 budget_usd: 30 effort: medium —

Issue #2723

Your work order is issue #2723, inlined below with its comments. There is no brief written around it: plan your own steps from its To build list, build them in order, commit after each finished step, and end when its Done when holds (or at the limits of builder.md, reporting what is left). The facts in your prompt are Core of docs/builder-facts.md; more on a topic: nikaia run scripts/syntax.nika -- KEYWORD, a probe: nikaia run scripts/probe.nika -- SNIPPET.

Measure the issue against docs/issues.md while you work: what it lacked, what was wrong in it. That answer goes into the report’s Issue: field. A finding, a changed plan or a finished item also goes into the issue as a comment (gh api repos/Nikaia-Foundation/Nikaia/issues/2723/comments -F body=@file, ending with the Claude Code footer), rule I13.

Rules (CLAUDE.md; shared checkout)

Report (at most 15 lines, to exactly /home/user/Nikaia/docs/briefs/safety/issue-2723.md.report.md)

Fields: Result, Files, Commit, Body (optional), Fixes, Pushed, Tests, Gate, Deviation, Found, Needs, Changelog, Issue, Owner (a question for the owner), Comment (#N <text>, what to say on another issue; the driver posts it, one line each), Friction, Disk freed, and last Attribution: with your commit trailer lines below it.


Generated by Claude Code

keywan-ghadami, 2026-11-22

Run: issue-2723, Result: blocked

Tokens: input 258, cache read 9899964, cache write 229814, output 64967 Cost: 5.45 USD, time 0 min 7 s, turns 129

Report

Result: blocked Pushed: none (D19 work saved, unpushed, on branch wip/issue-2723 bcb0fb3f: std list, prover, run-time throw, help, test, docs) Tests: new tests/compiler/tests/a_shell_named_as_the_program_is_a_raw_sink (13 cases) passes on the wip build and FAILED on the old binary; std runtime:: 24 passed; an_argument_of_process_run_is_a_raw_sink and raw_sinks_manifest_keys pass; clippy clean Gate: green Deviation: on the wip branch, case and .exe are ignored on every target; env’s NAME=VALUE operands are skipped; a shell sink carried through a function parameter is refused at compile time but gets no run-time throw under warn (D7’s mechanism keys on the call’s own program expression) Found: To build item 6 cannot be done: scripts/drive.nika:2482 runs sh -c "( '{exe}' run '{script}' -- --ci-wait {sha} '{log}' '{exit}' ) < /dev/null > /dev/null 2> '{err}' & echo $! > '{pid}'" (and drive.nika:1178 a detached measurement the same way), and std has no shell-free form: let child = process::spawn("sleep", ["60"]); println(f"{child.id()}") gives NK1171 “process::Child has no method called id.”; process::spawn("sleep", ["60"]; stdout: process::Stream::Inherited) gives NK1109 “process::spawn has no option called stdout.”; spawn always sets stdin to null and pipes stdout/stderr into memory, with no dir, env, file redirection or detach (outlive the parent) option; no ADR refuses these; run on target/fast/nikaia built from HEAD 2026-11-22; no decision yet Needs: supervisor decision: a detached process::spawn (pid, stdin/stdout/stderr to null or a file, outliving the parent) or another shell-free form for drive.nika:2482 and 1178; then wip/issue-2723 lands together with the rewrites of drive.nika (950, 1208, 1222, 1231, 1409, 1475, 1756, 1858-1900, 1983, 1997, 2335, 2383, 2946, 3511, 3519, 5747-5766), lower_mine.nika (mine_sh), ledgers.nika:251-252, analysis_cost.nika:443-455, benches/game and benches/hello, which the new prover refuses Changelog: none (nothing committed) Issue: fits docs/issues.md, but To build 6 assumes every script form can be written without a shell, and the detached background run cannot Owner: sudo -u root sh -c X slips past D19’s rule that a runner passes the check to its first operand, because the first operand is -u’s value root; the wip branch skips only - elements; should runners carry per-runner option tables? no decision yet Comment: #2723 D19 is built on branch wip/issue-2723 (bcb0fb3f): process::shells/runners/is_shell/is_runner in std, NK1308 shell kind in prover_walk, a run-time IoError::Other under warn, Part III and website text, a 13-case test. It cannot land yet: under the default warn our own scripts would throw at run time, and drive.nika:2482 (a detached & background run writing its pid) has no shell-free form, because process::Child has no id() and spawn has no stdio/detach options Friction: a new std fn used by the compiler’s own .nika (process::shells in prover_walk) gives NK1171 on the first lower-std, because the binary embeds the old std.contracts; it needed a bootstrap round (compiler files at HEAD, lower-std plus a build, then the files restored), about 10 turns; docs/builder-facts.md does not mention this Disk freed: none; target/nikaia-project-tests 1.6G, / 5.7G free (86 % used), no new cache entry over 100 MB; shared tree restored to HEAD (sources by name, lowered/ regenerated by lower-std plus build), git status clean of my files Attribution: Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com Claude-Session: https://claude.ai/code/session_01UVxJDvbkNUUMs8HdjJ8ixV

Debrief

  1. Most cost. The bootstrap round. New process::shells/is_shell used in prover_walk.nika gave NK1171 on the first lower-std, because the binary embeds the old std.contracts. It took about 10 turns and two cycles: compiler files temporarily set back to HEAD, then lower-std plus a build, then the files restored. Second was the check of all scripts and benches. It timed out in the foreground and showed the blocker only after the whole prover was built.
  2. Lookups. How D7’s run-time check is wired (walk.raw_paths to project_check_raw_path_checks to EmitState.raw_path_checks to emit_core_argument), the signature of process::spawn and Child, and where Part III 13.3 and 17 sit in 30-nikaia-tooling.md. The brief could have named all of these.
  3. Checks. Run: the new test (passes on the new binary, FAILED on the old one), std runtime:: tests, two neighbouring raw-sink tests, clippy, fmt, the scripts/benches deny scan. Wasted: building the full prover, help, docs and test before scanning scripts/ for shell forms that cannot be rewritten. One polling loop broke the wait-in-one-call rule.
  4. One change. builder.md should say: an issue that rewrites our own code to satisfy a new check runs that check over the code first (a grep for process::run("sh"), before any build. Here it would have found the blocker in about 3 turns, not 80.
  5. What the issue lacked.
    • broke I7: it claims every script can drop the shell, and no check settles that. The detached & run with a pid (drive.nika:2482, :1178) cannot.
    • rules-gap: no list of our own shell call sites by form (pipe, glob, redirect, background).
    • knowledge: Lowering | a new std fn used by the compiler's own .nika needs one lower-std and build with the compiler files at HEAD first, because the binary embeds std.contracts
  6. Traps.
    • Fact: Lowering | A std function first used inside crates/nikaia-std/src/compiler/*.nika draws NK1171 until a binary built with its std.contracts entry exists; bootstrap with the compiler files at HEAD, then restore them.
    • Fact: Core | process::spawn has no pid (Child.id), no stdio, dir or env options and no detach; a background shell run in a script has no shell-free form yet.
  7. Work area: raw sinks.
    • Fact: Raw sinks | The D7/D19 run-time check flows from prover_walk raw_paths (RawPathCheck, root -1 for D19) through project_check_raw_path_checks to emit_core_args emit_core_argument, keyed by node_key of the argument; measured 2026-11-22, wip/issue-2723 bcb0fb3f.
    • Fact: Raw sinks | The D19 prover refuses about 60 shell sites (2026-11-22, bcb0fb3f): drive.nika about 30, lower_mine 9, game 9, hello 10, analysis_cost 3, ledgers 2.

Generated by Claude Code

keywan-ghadami, 2026-11-22

From the report of the run of issue-2723 (#2723):

D19 is built on branch wip/issue-2723 (bcb0fb3f): process::shells/runners/is_shell/is_runner in std, NK1308 shell kind in prover_walk, a run-time IoError::Other under warn, Part III and website text, a 13-case test. It cannot land yet: under the default warn our own scripts would throw at run time, and drive.nika:2482 (a detached & background run writing its pid) has no shell-free form, because process::Child has no id() and spawn has no stdio/detach options


Generated by Claude Code

keywan-ghadami, 2026-11-22

Driver: not queued, this issue waits for #2748, which is still open (#1819). Set ready again when it is closed.


Generated by Claude Code

keywan-ghadami, 2026-11-22

Supervisor, 2026-11-22: run 1 is accepted as blocked. Its work is on wip/issue-2723 (bcb0fb3f) and lands after #2748.


Generated by Claude Code

keywan-ghadami, 2026-11-22

Driver: not queued, this issue waits for #2748, which is still open (#1819). Set ready again when it is closed.


Generated by Claude Code

keywan-ghadami, 2026-11-22

From the report of the run of issue-2748 (#2748):

process::spawn now takes run’s options with Stream::Discarded/File(path) and Child::id (ADR-243 D11, Fixes #2748): drive.nika’s detached sh -c "( ... ) & echo $! > pid" can be written as let child = process::spawn(exe, args; stdout: process::Stream::Discarded, stderr: process::Stream::File(err)) then writing child.id(); the File path must be text of its own (an f-string), and spawn’s program is not yet a raw sink like run’s.


Generated by Claude Code

Back to Open Issues