Open and answer this issue on GitHub.
blocked, safety · opened 2026-11-14 · updated 2026-11-16 · 2 comments
Found while checking #669 (closed 2026-11-14): env::var, env::temp_dir and env::current_exe are built, but there is no way to list the environment. The owner decided on 2026-11-14 that reading environment variables is basic functionality, so the list is built. The owner also decided that the environment is data from outside, treated like every other outside data: it is untrusted, and where it goes (a log, output) it is escaped as untrusted data is, never written raw. That is recorded as ADR-397 (changes ADR-010 D2, as ADR-365 did for standard input and files), commit b9c9b9d.
ADR-397 (owner, 2026-11-14):
env::var and env::vars is untrusted. An assert about it is NK1202, an index it reaches is proved or refused (NK1302, ADR-396), and a map keyed by it gets the keyed hash. env::temp_dir and env::current_exe give paths, and no provenance travels a path (ADR-010 D8, ADR-108).trusted: true at the source (env::var("X"; trusted: true)) says the operator chose it. The ledger records the marker with its place.env::vars (supervisor, by the language principles; text goes into the specification with item 1): env::vars(prefix: String) -> [(String, String)] returns every variable whose name starts with prefix, as (name, value) pairs, sorted by name.
The safety rules, and why each one is there:
prefix is required. env::vars("") lists everything, but the caller has to write that.
AWS_*). A program that needs APP_* should not get the rest. The normal case (configuration under one prefix) then asks for exactly what it uses.env::var. A variable that is empty or not Unicode is left out of the list, so vars never shows a variable that var reports as null.
std::env::vars() panics on a non-Unicode name or value. A program that crashes because of what its caller put in the environment is a denial of service. Built on vars_os (or the equivalent) with a filter.set_var / remove_var. This issue only reads.
unsafe in Rust 2024 because another thread or a C library may read it at the same moment.process::run(...; env:, env_clear:, env_remove:) (ADR-243 D5).env::var, trust by ADR-397.
sync, no touches line, so it orders against every other effect (Part III 13.5).trusted: true as for env::var (D2).env::var and env::vars hand back untrusted text, and trusted: true marks it trusted and is recorded in the ledger; --trust shows both.env::vars(prefix) returns the pairs as described and the specification documents it.docs/specification/30-nikaia-tooling.md, std::env (around line 1523; the trust sentence from ADR-397 is already there):
env::vars(prefix: String) -> [(String, String)] with rules 1-3 and the warning of rule 6, and its trusted: option.sync” becomes “All four”.env::var is untrusted (ADR-397 D1, D2), in the provenance the compiler keeps for std’s sources, where standard input and fs reads are classified (ADR-365; crates/nikaia-std/src/tools/trust.nika, the ledger’s trusted: markers in ledger.nika), written in Nikaia.
tests/compiler/tests/a_file_or_stdin_read_is_untrusted_unless_marked.nika: an assert about env::var("X") is refused with NK1202; the same with trusted: true is checked.trusted: true on env::var appears in the ledger, as in trusted_markers_are_recorded_in_the_ledger.nika.trusted: true where the operator chose the value (a test runner’s own setting). The report lists every place and which.env::vars in std, written in Nikaia (CLAUDE.md, Written in Nikaia only), next to crates/nikaia-std/src/env.rs, untrusted like env::var.
Result: blocked, Found: the missing primitive, Needs: supervisor decision.tests/compiler/tests/env_vars.nika with .stdout, built like env_var.nika. It starts itself as a child with process::run(me, ["child"]; env_clear: true, env: [("NIKAIA_V_B", "2"), ("NIKAIA_V_A", "1"), ("NIKAIA_V_EMPTY", ""), ("OTHER", "x")]).env::vars("NIKAIA_V_"). Expected rows, in this order: NIKAIA_V_A=1, NIKAIA_V_B=2. The empty variable and OTHER are missing.env::vars(""), which is 3: everything except the empty one.0xFF 0xFE, if process::run can pass bytes.env::vars("") leaves it out and does not panic.process::run cannot pass non-Unicode bytes, say so in the report. That is a finding, not a workaround.docs/specification/30-nikaia-tooling.md, std’s env module, the provenance of std’s sources (trust.nika, ledger.nika and what lowers from them), the places in our own code item 2 names, tests/compiler/tests/env_vars.* and the new trust tests.env::var returns (env_var.stdout stays byte-identical). No set_var. The ADRs (ADR-397 is decided).trusted: false as the way out: fails open when the marker is forgotten (ADR-397 §2).vars() without a prefix: it hands every secret to code that needed one variable (rule 1).std::env::vars() (rule 2).process::run’s env: and keeps the order fixed.Brief queued: issue-1597
agent: builder model: opus max_turns: 200 budget_usd: 30 effort: medium —
Your work order is issue #1597, 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/1597/comments -F body=@file,
ending with the Claude Code footer), rule I13.
develop in the main checkout; other agents’ uncommitted files are not yours: never touch or stage them.target/fast/nikaia run scripts/commit.nika -- REPORT (it adds exactly the report’s Files:); the driver pushes.cargo build --profile fast -p nikaia, lower-std and its fixpoint when a tools/*.nika changed, cargo fmt, cargo clippy --all-targets -- -D warnings, nikaia run scripts/pre-push.nika, the tests the issue names and the ones your change touches.CHANGELOG.md, badges and NK codes are the supervisor’s. New tests in Nikaia only.Body:. Found: is only for what lies outside the area, cannot be fixed this run or needs a decision; the driver files it as an issue.std or the toolchain lacks stops the work, unless an ADR or Part I-III refuses it (name it): Result: blocked, Found: the gap with a probe, Needs: supervisor decision.NIKAIA_CACHE_LIMIT=2G; at the end delete your own clone’s target/ and target/release/nikaia-scratch.Result: partial with what you ruled out, the probe, and the suspected file and function./home/user/Nikaia/docs/briefs/trust/issue-1597.md.report.md)Fields: Result, Files, Commit, Body (optional), Fixes, Pushed, Tests, Gate, Deviation, Found, Needs, Changelog, Issue, Owner (a question for the owner), Disk freed, and last Attribution: with your commit trailer lines below it.
Result:, Gate: (green or red <check>), Deviation:, Found: and the other fields with nothing to say hold the bare word: done, none. Anything after it reads as content.Result: done only when the issue’s Done when holds; partial with the items left otherwise.Deviation: only for an item of the issue built otherwise than written, or not built. Found: only for a defect outside your area, or one this run cannot fix. Everything else goes into Body:; how you verified goes into Tests:.Issue: by docs/issues.md, How a run judges its issue: complete, or broke I<n>: ..., rules-gap: ..., wrong I<n>: ..., joined with ;.done <sha>, report <path> (or BLOCKED: ... / PUSH REJECTED ...).Generated by Claude Code
Run: issue-1597, Result: blocked
Tokens: input 84, cache read 2330890, cache write 65063, output 17238 Cost: 2.71 USD, time 11 min 14 s, turns 42
Result: blocked
Files: crates/nikaia-std/std.contracts docs/specification/30-nikaia-tooling.md tests/compiler/tests/an_environment_variable_is_untrusted_unless_marked.nika tests/compiler/tests/an_environment_variable_is_untrusted_unless_marked.stdout
Commit: env::var is an untrusted source unless marked trusted: true (ADR-397)
Body: std’s ledger gives env::var provenance = "untrusted" and the option trusted: bool = false (ADR-397 D1, D2), so an assert about it is NK1202, a map keyed by it gets the keyed hash, and trusted: true is checked as any claim, named by --trust and recorded in the ledger. No Rust and no .nika changed: the checker, prover and ledger already read provenance from std’s ledger. Our own code: no place asserts about or keys a map with an environment value (lower-std left lowered/ unchanged; scripts/drive.nika, scripts/gate.nika check as before; no use in tests/accepted or packages), so no guard and no marker was added. The specification’s std::env documents env::vars(prefix) (rules 1-4, 6, trusted:), “All four”.
Part: #1597
Pushed: local 194d42b5365eb06193207d1751548cdd7d45bda1
Tests: new an_environment_variable_is_untrusted_unless_marked passes on the new binary and FAILED on the before binary (no NK1202, trusted: was NK1109, no –trust line); env_var (stdout byte-identical), a_lent_match_binding_is_the_pattern_of_a_text_method_as_it_is, a_file_or_stdin_read_is_untrusted_unless_marked, trusted_markers_are_recorded_in_the_ledger pass –both-settings; lower-std clean with no lowered change; pre-push green
Gate: green
Deviation: items 3-4 (env::vars in std, its env_vars test, the non-Unicode test) not built: blocked on a missing primitive, below; the trust test is one new program covering the assert, guard, trusted: true, –trust and the ledger record, instead of also extending trusted_markers_are_recorded_in_the_ledger
Found: (1) no Nikaia path lists the environment: std has no primitive for it (env.rs has only var, temp_dir; ADR-302 foreign calls cannot walk C’s environ, a global, not a function), so env::vars needs a new Rust primitive in crates/nikaia-std/src/env.rs (built on std::env::vars_os, filtering empty and non-Unicode, sorted) plus its ledger entry; probe: use std::env\nfn main() throws { println(env::vars("").len()) } gives NK1171 env has no function called vars. (2) process::run’s env: is Vec[(String, String)], so a test cannot hand a child a non-Unicode value (item 4). (3) env::current_exe is in the specification (30-nikaia-tooling.md std::env) and #669 is called closed, but it is neither in env.rs nor in std.contracts. (4) ADR-399 makes cli::args untrusted, but std.contracts still marks cli::args and cli::Args::* provenance = "trusted".
Needs: supervisor decision: a Rust primitive for listing the environment in crates/nikaia-std/src/env.rs (the one function item 3 needs), or another way to reach it from Nikaia
Changelog: env::var is untrusted (ADR-397): an assert about an environment value is NK1202 unless the call says trusted: true, maps keyed by it get the keyed hash, and the marker is recorded in the ledger; the specification documents env::vars(prefix).
Issue: wrong I7: the provenance of std’s sources is the provenance column of crates/nikaia-std/std.contracts, not trust.nika or ledger.nika (they read it), so item 2 was a ledger edit; wrong I9: item 3 orders env::vars “written in Nikaia” though no primitive to list the environment exists, which the issue foresaw only as a stop
Owner: none
Disk freed: none; target/nikaia-project-tests 7.3G (over the 2G limit before this run), / 8.7G free, no new cache entry over 100 MB
Attribution:
Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com
Claude-Session: https://claude.ai/code/session_01UVxJDv4ha75BSeuJhmqFAL
trust.nika and ledger.nika, but the classification is the provenance column in crates/nikaia-std/std.contracts. It took about 8 turns of grep. The lower-std run (4 minutes) and a broad grep -r over tests/ that timed out cost wall time too.provenance plus the ; trusted: bool = false option in std.contracts); that prover_calls.nika reads it from the ledger, so no code change was needed; whether anything can list the environment from Nikaia (env.rs, ADR-302 foreign calls); and what process::run’s env: takes.--both-settings; check of scripts/drive.nika and scripts/gate.nika; pre-push.lower-std. Only the ledger changed and lowered/ came out unchanged, though it did confirm our own code was unaffected. Also the background grep -r tests/.std.contracts (provenance, trusted: option); a new source is a ledger edit, not a .nika change”. It should also say whether a new Rust primitive in env.rs is pre-approved for env::vars.trust.nika and ledger.nika as where provenance lives; it is std.contracts.env::vars “in Nikaia”, but no primitive to list the environment exists. The blocker was foreseeable and could have been decided before the run.env::vars missing (NK1171) or env::var currently trusted.env::current_exe is built (#669), which is false.| Fact: Core | A std source’s trust is the provenance line plus the trusted: bool = false option in crates/nikaia-std/std.contracts; the checker and prover read it from there, so making a source untrusted needs no .nika change. |
| Fact: Core | std.contracts is compiled into the binary (include_str!), so a ledger edit needs only cargo build; lower-std changes nothing unless a tool file uses that source. |
| Fact: Core | process::run’s env: is Vec[(String, String)], so no test can hand a child a non-Unicode variable. |
Generated by Claude Code