Skip to content

fix(security): read_file withholds a file with more than one hard link - #709

Merged
ajianaz merged 1 commit into
developfrom
fix/hardlink-sensitive
Nov 14, 2026
Merged

ajianaz merged 1 commit into
developfrom
fix/hardlink-sensitive

Conversation

@ajianaz

@ajianaz ajianaz commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

What

read_file refuses a regular file that has more than one hard link (Unix only) and points to read_file_raw.

Why

A hard link to .env under an innocuous name (notes.txt) matches neither the requested-name rule nor the canonical-path rule, so read_file (ReadOnly, no approval) returned it verbatim. Left over from #683.

Changes

  • sensitive.rs: has_other_names(&Metadata), true when is_file() && nlink() > 1 on Unix, always false elsewhere.
  • read_file.rs: read_regular checks it on the open handle for read_file; read_file_raw skips it. The error names read_file_raw.
  • Only metadata().nlink(), no directory scan. The git diff filter and cora_search hits stay name-based (they have no file handle to stat).
  • CHANGELOG entry (Security) and the stale "not detected yet" note updated.
  • Trade-off: a legitimately hard-linked file also needs read_file_raw.

Testing

  • New test: hard link to .env is withheld (error names read_file_raw, no secret in it), a single-link file reads, read_file_raw reads the linked file, and after removing the other name it reads again.
  • Mutation check: raising the threshold to nlink > 1000 makes the test fail.
  • fmt, clippy --workspace --all-targets --all-features -D warnings, cargo test --workspace, tole-core --no-default-features pass, except tole-cli doctor_warns_non_fatally_about_a_missing_window and agents::parent_spawns_child_polls_until_settled, which fail the same way on unmodified develop in my sandbox (cora MCP not approved in the plugin lock).

Closes #703

A hard link to .env under another name matched no name rule and was read
verbatim. On Unix a regular file with nlink > 1 is now refused and the
refusal points to read_file_raw. Only metadata().nlink(); no scan; no-op
on other platforms.

Closes #703
@ajianaz
ajianaz force-pushed the fix/hardlink-sensitive branch from 47b2b43 to 6e45660 Compare November 14, 2026 05:41
@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 051f72c into develop Nov 14, 2026
15 checks passed
@ajianaz
ajianaz deleted the fix/hardlink-sensitive branch November 20, 2026 08:39
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.

security(files): a hard link to a sensitive file under another name is read verbatim

2 participants