Skip to content

fix(repo): refuse a commit that would store a protected file as plaintext after its rule was dropped - #364

Merged
tonibergholm-codento merged 4 commits into
mainfrom
fix/commit-unruled-protected
Nov 20, 2026
Merged

tonibergholm-codento merged 4 commits into
mainfrom
fix/commit-unruled-protected

Conversation

@tonibergholm-codento

Copy link
Copy Markdown
Collaborator

Protection rules are repository data. A writer could push a commit that keeps a protected file's entry but drops the rule covering it. A recipient who switched to that commit with their key had the decrypted file on disk. Their next ordinary sc commit then stored it as plaintext, with only the secret scanner in the way. A test reproduced this before the fix.

Now snapshot_files, the builder shared by commit, amend, merge, pick and rebase completion, sc ws harvest and sc work, refuses before writing any object in three cases:

  • A tip entry is protected and no rule in the new protection covers it. This covers a dropped rule, a new plain file under a dropped rule, and a keyless commit that would silently drop absent protected entries.
  • On a completion, a path that would land as plaintext is protected on the other parent. This check uses point lookups only; a lazy, online partial clone fetches the missing trees for them, and any other clone keeps the gap error with its sc backfill hint.
  • A plain path matches a rule prefix or protected path ignoring case, and it is the same file on disk. This is the case on APFS or NTFS, where checkout can lay secret/x into an existing Secret/ directory. Distinct paths on a case-sensitive filesystem pass.

No normal flow produces a protected entry without a rule, since merges union rules. The full scl-repo suite passes unchanged apart from the new tests. While a merge, pick or rebase is stopped, the error says to abort, restore the rule and retry.

Proof: new tests in repo.rs and partial_merge.rs:

  • a_commit_never_stores_plaintext_of_a_path_whose_rule_was_dropped_upstream failed on the old code with the plaintext committed.
  • The rest cover the new-file case, the keyless case, the case-alias cases, the stopped-operation hint and the widened partial merge.

cargo test -p scl-repo passes: 1087 tests.

Reviewed with sol-loop: 4 rounds with gpt-6.2-sol. Sol verdict: approved. A Mythos security review asked for the broader guard and the case-alias check; both are in.

Created with Claude Opus 5.5 and Claude Sonnet 5.5 in Claude Code.

… rule was dropped upstream

Protection rules are repository data. A tip that keeps a path's PROTECTED
entry but omits its rule made a recipient's checkout hold the plaintext, and
the next ordinary commit stored it unsealed. snapshot_files (commit, amend,
completion, ws harvest, sc work) now refuses before writing any object when a
working-tree path is PROTECTED on the tip or the merge/pick head and no rule
covers it.
…d entry

Refuse when any tip entry is PROTECTED and no rule in the new protection
covers it (new plain files under the dropped rule, keyless commits dropping
absent entries), check the merge/pick head by point lookups for plain paths
only so a partial clone never walks an unheld subtree, and refuse plain paths
that differ only in ASCII case from a rule prefix or protected tip path. The
hint says to abort while a merge, pick or rebase is stopped.
…loaded trees

The dropped-rule guard walked the merge/pick head's path with a plain store
lookup, so a widened partial-clone merge failed on a tree it never held. It
now fetches the missing trees by id on a lazy, online clone (any other clone
keeps the gap error with its `sc backfill` hint) and keeps the trees it loaded
in a per-guard map, so a flat directory is read once.

The case-alias refusal now also requires the protected spelling to be the same
file or directory as the plain path in the checkout the commit reads from
(device and inode on unix, always assumed elsewhere), so a distinct
`docs/private/` beside a rule `Docs/private/` commits on a case-sensitive
filesystem. snapshot_files takes that checkout root.
The guard folded and scanned every protected tip path for every plain file.
It now builds a folded-spelling map of protected tip paths and rule prefixes
once and looks up each plain path and its parent directories, running the
device/inode comparison only on a match. The alias tests expect a refusal off
unix too, where the identity check always assumes aliasing, and the
distinct-path test creates both directories on disk.
@coderabbitai

coderabbitai Bot commented Nov 20, 2026

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a56a4564-2124-414a-a7be-8c86812a3709
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-20T09:22:03.216761Z bcf31d8 PR opened
🔒 Security Review ✅ Completed 2026-11-20T09:24:40.787457Z bcf31d8 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@tonibergholm tonibergholm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed: sol-loop (4 rounds, approved) plus a Mythos security review, required checks green, Codex review has no findings.

@tonibergholm-codento
tonibergholm-codento merged commit 76602cb into main Nov 20, 2026
11 checks passed
@tonibergholm-codento
tonibergholm-codento deleted the fix/commit-unruled-protected branch November 20, 2026 09: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.

2 participants