Skip to content

feat(secrets): sensitive files read redacted, approved raw reads, doctor report - #632

Merged
ajianaz merged 1 commit into
developfrom
feat/sensitive-path-reads
Nov 12, 2026
Merged

ajianaz merged 1 commit into
developfrom
feat/sensitive-path-reads

Conversation

@ajianaz

@ajianaz ajianaz commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

What

#598 part (b). Sensitive files (.env*, *.pem, id_*, .npmrc, .netrc, *.key) never come back verbatim from a tool that returns file bytes. read_file shows KEY=«redacted», and a verbatim read is a separate, approval-gated tool, read_file_raw (Risk::Write). tole doctor gains a secrets report that shows names only.

Why

Owner decision 2026-11-11 (docs/secrets-integrations-design.md §4). A .env inside the workspace was readable verbatim, so its values entered the model's context and the session log. AI-assisted code leaks secrets at about twice the baseline (GitGuardian 2026).

Changes

  • tole-core/src/sensitive.rs (new):
    • is_sensitive_name: matches the file name, case-insensitive.
    • is_sensitive_path(requested, real): true when the name the tool was asked for OR the resolved real path matches, so a symlink notes.txt -> .env is sensitive.
    • redact_content: blank lines stay, KEY=value becomes KEY=«redacted», and every other line becomes the marker (comments included, since they can hold values). A key or pem file becomes a single «redacted».
    • redact_diff: in a sensitive file's diff section, headers and hunk ranges stay, every hunk line becomes +«redacted», -«redacted» or «redacted», and the file text git prints after a hunk range is dropped.
    • redact_hits: a search hit that names a sensitive file keeps its path; every other string field, at any depth, becomes the marker.
  • read_file:
    • A sensitive file returns redacted content, redacted: true, and a note naming read_file_raw.
    • It returns no content hash: a 64-bit DefaultHasher of a short secret could be brute-forced offline, and editing such a file needs the verbatim read anyway.
    • FIFO safety: the file is opened with O_NONBLOCK|O_NOFOLLOW, checked on the open handle (regular file, size cap) and read through take(cap+1), so a FIFO or a file swapped in after the check cannot hang or bloat the read.
  • read_file_raw (new, ReadFileTool::raw): Risk::Write, so each call needs approval, or an explicit --allow read_file_raw (the only way in a mission). It is a risk tier, not an environment opt-out. It is registered in plan mode too, since it writes nothing.
  • git tool: stdout passes through redact_diff.
  • cora_search: the JSON passes through redact_hits.
  • tole doctor: a "secrets (names only)" block:
    • each secret-named variable that is set, with the tools its [secrets] release lets receive it, marked ! when that includes run_command, job_start or cron;
    • what the children of model commands receive;
    • what a child session receives;
    • how to approve a verbatim read.
  • Docs:
    • a CHANGELOG entry under Security;
    • docs/secrets-integrations-design.md §10, with the tool table and how to approve;
    • a threat-model row, "Sensitive data disclosure (files)";
    • a README note.

Every tool that can return file bytes, and what it does with a sensitive file:

Tool Behaviour
read_file KEY=«redacted» lines; a key or pem file one marker; no hash
read_file_raw (new) verbatim, after approval (Risk::Write)
git diff hunk lines and the text after hunk ranges redacted; headers and ranges kept
git status names only (unchanged)
cora_search the path is kept; snippet and other text redacted
edit_file, write_file, delete_file never return content (edit_file needs the hash, so it needs read_file_raw first)
run_command, job_start / job_poll output is not path-filtered: any command can read any file. They are approval-gated, and SecretSet redacts known secret values on egress (documented residual)
MCP tools, web_fetch, gh server or URL content, not workspace files

There is no separate search, grep, list or diff tool: search is cora_search (or a command), and diff is the git tool.

Testing

All run locally on 0117e9f (develop 9f66f13), with CARGO_TARGET_DIR set and CARGO_INCREMENTAL=0.

  • cargo test --workspace --no-fail-fast passes: 1564 passed, 0 failed (84 suites).
  • cargo test -p tole-core --no-default-features passes: 545 passed; cargo check -p tole-core --no-default-features --tests passes.
  • cargo test -p tole-cli --no-default-features passes: 463 passed; with --features shell-tools added, 626 passed. These ran on the commit before the final clippy and fixture-text fix, which changed no behaviour; the tole-core sensitive and read_file tests were rerun on the final head.
  • cargo fmt --all -- --check passes.
  • cargo clippy -D warnings passes for --workspace --all-targets, -p tole-core --no-default-features --all-targets, -p tole-cli --no-default-features and -p tole-cli --no-default-features --features shell-tools.
  • cora review --no-llm --staged: "No issues found". Its first run flagged the fake private-key block in a test fixture; the fixture is now neutral text.

New tests:

  • sensitive::tests:
    • names match case-insensitively, plus near misses that must not match (env.rs, my.envelope, npmrc);
    • the requested name or the real path;
    • .env line redaction (export, spaces around =, \r\n, comments);
    • a key file becomes one marker;
    • a diff with one ordinary and one sensitive file;
    • search-hit JSON.
  • read_file::tests::sensitive_files_read_redacted_and_raw_only_with_approval:
    • .env, Server.PEM, .ENV.Local, and a symlink notes.txt -> .env;
    • no hash and a note naming read_file_raw;
    • read_file_raw is Risk::Write and returns verbatim content with a hash;
    • an ordinary file is untouched.
  • read_file::tests::a_fifo_never_hangs_the_read: a FIFO named .env errors within 5 s instead of blocking.
  • git::tests::a_diff_hides_the_lines_of_a_sensitive_file: end to end through a fake git binary.
  • doctor::tests::the_secrets_report_names_secrets_and_their_tools_never_values:
    • no value ever printed, and non-secret variables not listed;
    • the per-secret tools, the ! on a command grant, the command-children line and the child-session line;
    • with the default release, "no secret".

Red/green: each rule was broken on purpose, the named test failed, and it passed again once restored. All 13 breaks were caught:

Broken rule Caught by
case-sensitive name match names test, read_file test
real path not checked (symlink leak) names test, read_file test
values kept in env lines redaction test, read_file test
key file shown line by line redaction test, read_file test
text after a hunk range kept diff test
search hits not redacted hits test
read_file returns the raw content read_file test
hash kept for a sensitive file read_file test
read_file_raw not approval-gated read_file test
FIFO opened blocking FIFO test (fails after 5 s; the older FIFO test then blocks too)
git diff not redacted git test
doctor prints a value doctor test
doctor does not flag a command grant doctor test

Size: 648 changed lines (610 added, 38 removed) across 11 files.

Related Issues

Part (b) of #598 (secrets epic #594; follows #631).

Checklist

  • Branch name follows convention (feat/sensitive-path-reads)
  • Branch is from develop
  • Commit messages follow Conventional Commits
  • No secrets or credentials committed
  • One logical change per PR

…tor report

#598 part b (design secrets-integrations §4). read_file on .env*,
*.pem, id_*, .npmrc, .netrc or *.key (file name, case-insensitive, by
the requested name or the resolved real path, so a symlink to .env
counts) returns KEY=«redacted» lines, a key file one marker, and no
content hash. The verbatim read is the new read_file_raw tool,
Risk::Write: approve its call or start with --allow read_file_raw.

The git tool's diff hides every hunk line of a sensitive file and the
text after its hunk ranges; cora_search hides the text of a hit in one.
read_file now opens with O_NONBLOCK|O_NOFOLLOW, checks the open handle
and reads with a cap, so a FIFO or a file swapped in after the check
cannot hang or bloat the read.

tole doctor adds a secrets report, names only: which secret names are
set, which tools may receive each (flagged when a model command may),
what reaches the children of model commands and of a child session, and
how to approve a verbatim read.
@github-actions

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

@ajianaz
ajianaz merged commit e76d90e into develop Nov 12, 2026
19 of 20 checks passed
@ajianaz
ajianaz deleted the feat/sensitive-path-reads branch November 20, 2026 08:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants