ADR-399: Command-Line Arguments Are Untrusted Unless Marked trusted: true

Status: Accepted Date: November 14, 2026 Answers: who chose the words a program is started with, which ADR-010 D2 answered the operator and ADR-365 and ADR-397 left open; what a claim about one is; what a value made from one may reach Related: ADR-010 D2, D3, D5, D7 (the sources, the marker at the source, the hasher, --trust); ADR-cli-v1 D3, D4 (main’s parameters and where their preconditions are checked); ADR-269 D6 (data from outside is checked where it arrives); ADR-365, ADR-397 (standard input, files, the environment); ADR-398 (the log escapes untrusted text); Part III 17.1

1. Question

let names = cli::args()
let mut seen: HashMap[String, int] = HashMap::new()
for name in names { seen.insert(name, 1) }
eprintln(f"first word: {cli::args().nth(1) ?? ""}")

ADR-010 D2 took the operator to have chosen the command line, so seen gets the fast, fixed-seed hash and the last line writes the word as it is. The operator is often not who chose the words: find . | xargs prog and prog *.txt hand over file names anyone who can write the directory chose; a web server, a job runner or a CI job builds a command line from a request or a pull request; a program run with more rights than its caller (setuid, sudo) takes its words from the caller. A file name with a line feed or ESC [ 2 J in it is a legal name. The same bytes through standard input, a file or the environment are untrusted (ADR-365, ADR-397). (Changed by ADR-397, November 19, 2026: the environment is the operator’s except a CGI host’s names and a privileged start.)

2. Options

Option Why it lost See
Keep them trusted; trusted: false at the source the unsafe answer when the marker is forgotten: an analysis that fails open (ADR-010 D2’s own rule, ADR-365’s and ADR-397’s reason) D1
Untrusted only when the program runs with more rights than its caller the program cannot see who built its command line; xargs and a glob hand over strangers’ names with no rights changed D1

3. Decision

D1 — Every word of the command line is untrusted.

cli::args() hands back untrusted words, and so do main’s parameters (ADR-cli-v1 D1), which are read from them. A map keyed by such a value gets the keyed hash (ADR-010 D5), the log escapes it (ADR-398), and the value keeps its provenance through every value made from it (Part III 17.1).

D2 — A claim about a word is checked where it arrives.

main’s preconditions are already checked where the words arrive and end the program with status 2 (ADR-cli-v1 D4); nothing changes there, and a claim about main’s parameters stays allowed. A claim about a word read with cli::args() is a claim about outside data and is refused (NK1202, ADR-269 D6), as one about a line of standard input is; the program checks the word, or takes it as a parameter of main.

D3 — trusted: true at the source says the operator chose them.

cli::args(trusted: true) hands back trusted words: a claim about one is checked as any claim is, and its maps may take the fast hash. The marker is recorded in the ledger with its place, so a review finds every one (ADR-010 D3), and --trust names it (ADR-010 D7).

4. Reasons

5. Consequences

main’s signature takes no trusted marker (owner, November 14, 2026): its parameters stay untrusted, and a program that needs the words trusted reads cli::args(trusted: true). The build’s own parameters at compile time (ADR-287 D14) are compile-time data and stay trusted.

Decided November 14, 2026.

This site is open source. Improve this page.