Skip to content

fix(repo): seal only to recipients this clone accepted, so a writer cannot add themselves - #368

Merged
tonibergholm-codento merged 10 commits into
mainfrom
fix/accepted-recipients
Nov 20, 2026
Merged

tonibergholm-codento merged 10 commits into
mainfrom
fix/accepted-recipients

Conversation

@tonibergholm-codento

Copy link
Copy Markdown
Collaborator

Protection rules, secret wrap lists and private-branch key labels are unsigned repository data, so any writer could make themselves a recipient. A writer without a key could commit a narrower sc protect rule granting only their own key. After a merge or a fast-forward, the victim's next commit sealed changed files to the attacker, and sc rewrap re-wrapped existing keys to them. A teammate listed in recipients.toml could also append a bogus wrap label and be included in the next secret rotate or branch revoke. Nothing in merge, log or diff output showed any of this.

This adds a local, never-transferred record, .sc/accepted-recipients, and checks it wherever a key from committed data is actually wrapped (ADR-0059, amending ADR-0025 and ADR-0027).

Where it is checked.

  • Every seal through encrypt_protected: commit, amend, merge, pick and rebase completion, sc ws harvest and refresh, sc work, cherry-pick, rebase and branch publish.
  • sc protect, which checks before any ref moves.
  • sc secret rotate, sc secret grant, sc rewrap (an unaccepted entry is skipped and the command exits 1) and sc branch revoke.
  • Carries that copy existing wraps mint none and are not gated.

What counts as accepted.

  • Keys the user names on the command line, recorded only after the command validates and before its ref moves.
  • Keys in the local [escrow] list, read at check time and never recorded.
  • Keys added with the new sc policy accept <scope> --key <key>.
  • sc policy forget <scope> <key> removes one. A local revoke also removes the pair.

Refusals. A refusal names the scope, the key and its local name, and prints the exact accept and revoke commands, escaped. Repository text is escaped in the related listings too.

Hardening from review.

  • secret grant, rotate and rewrap refuse a registry entry whose name differs from the name the secret is authenticated under.
  • The record is written durably under a lock.
  • Approvals for a single call are passed into that call; nothing is shared state.
  • sc protect --list exits quietly on a closed pipe.

Migration. The record starts empty and is not seeded from the tip, since the tip may already be poisoned. In each existing clone, the first seal to a key this clone has not named or accepted refuses and lists what to accept. CI should provision the record from trusted configuration. All 14 demos pass unchanged, because they name their keys.

Not covered (documented in the ADR, THREAT-MODEL and ROADMAP).

  • Protected ciphertext is not bound to its path.
  • The private-branch key generation is not pinned.
  • A writer can still replace a secret's value.
  • A revoke made in another clone does not reach this clone's record.
  • Any writer can block seals by adding a key.
  • An interrupted command can leave the approval it was about to record.
  • The record's integrity depends on the .sc/ path guard (fix(checkout): stop a cloned tree from writing into .sc/ or escaping the checkout #367).

Proof: 20+ tests in accepted.rs and crates/cli/tests/policy_accept.rs. The core gate tests failed with the gate disabled. They cover:

  • a narrower rule refused until accepted (fast-forward, fresh clone, merge, a key listed in recipients.toml)
  • planted secret and branch labels
  • protect accepting its own keys but refusing a foreign one before a ref moves
  • carry-only commits passing
  • a stopped merge completing after an accept
  • the record never transferring
  • a cloned tree unable to plant the record
  • refused grants and rotates recording nothing
  • relabeled secrets refused
  • concurrent accepts

cargo test -p scl-repo -p scl-cli passes, and so do the revoke, protect, rewrap, private-branch and lifecycle demos after the rebase.

Reviewed with sol-loop: 5 rounds with gpt-6.2-sol. Sol verdict: approved. Mythos designed the mechanism, and Sol reviewed the design before implementation. A Mythos security review of the implementation found the message escaping and the dependency on the path guard; both are addressed.

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

Protection rules, secret wrap lists and private-branch KEK wrap labels are
repository data, so a writer with no key could grant their own key and wait
for the victim's next commit, merge or replay reseal, rewrap, secret rotate or
branch revoke to wrap a DEK to them.

.sc/accepted-recipients is a local record of the recipient ids accepted per
scope (path:<prefix>, secret:<NAME>, branch:<name>); local [escrow] keys count
everywhere. encrypt_protected, the one function that turns a rule into wraps,
refuses before sealing anything when a key is not accepted for the winning
rule's prefix. sc protect validates the candidate rule before its first ref
move, secret_rotate and branch_revoke check the final set, and rewrap skips an
entry with an unaccepted key. Carries that copy existing wraps are not gated.

Keys named by the caller are accepted on the spot (protect, grant, secret
add/grant, branch --private, branch grant); the local revoke operations drop
the pair. The record is written atomically under the repo lock and is never
committed, packed or transferred. The test seams that hand-build rules accept
the keys they name.

Refs ADR-0059.
sc policy accept <scope> --key <scl-pk|id>[,...] records recipients in the
local .sc/accepted-recipients; a key in neither [recipients] nor [escrow]
needs --allow-unknown. sc policy forget removes one. Both touch only the local
file, so they work while a merge, pick or rebase is stopped and a refused
completion can be retried.

sc secret rotate --to accepts the keys it names, since the library cannot tell
a named set from one derived from the secret's own wrap labels. The rewrap hint
now mentions the accept route for skipped entries.

Refs ADR-0059.
Records the problem, the local accepted-recipients record, the gate sites, the
auto-accept rule, the migration, the alternatives rejected (seal only to
recipients.toml; signed policy) and the deferred items and residual risks.
Adds the matching THREAT-MODEL entries (Protected paths, with one line each
under Committed secrets and Private branches), a CLAUDE.md standing-boundary
bullet, the ADR index row, and status pointers on ADR-0025 and ADR-0027.
Escrow keys are no longer recorded as approvals. protect and secret add
persist only the keys the user named (the library drops the keys currently in
[escrow] from what it records, the CLI records the named ones), and private
branch creation records the creator and the named recipients only, so removing
a key from [escrow] withdraws its acceptance.

The three local revokes drop the approval after validation and before the new
ref is published, so an interruption cannot leave an approval outliving a
landed revoke.

sc policy accept validates the whole batch and writes the record once; a
path: scope with an id that has no key behind it is an error even with
--allow-unknown.

Refusal messages escape every repository-controlled field with
sanitize_display_line and print no command for a scope with control
characters. A Remove target that starts with "-" is written flags first and
after "--".

The shared seal path loads the record only when something is sealed, and
rewrap loads it at the first entry that wraps anything, so a commit that
wraps nothing no longer depends on the record being readable.

The ADR notes that the record's integrity depends on the working-tree path
guard.
…ment revoke gap

The suggested Remove command is always "flags, --, target", so a target that
starts with "-" cannot be read as a flag (the check ran after quoting before,
so it never fired). The shell quoting is POSIX only, as its comment says.

sc rewrap prints its skipped entries through sanitize_display_line: they carry
paths and names from the repository.

sc policy accept warns when a path: scope names no rule at the tip, and still
records it.

An ignored test (needs PR #367) pins that a cloned tree holding
.sc/accepted-recipients or .sc/recipients.toml is refused, since the record's
integrity does not rest on this change alone.

ADR-0059, THREAT-MODEL and ROADMAP record the residual risk that a revoke made
in another clone leaves this clone's acceptance in place, and the follow-on of
recording the grant epoch with each path: pair.
…ecrets in rewrap

rewrap skips a registry entry sealed under another name before opening it, as
secret_rotate refuses it: it would otherwise be approved by the registry name
and resealed under the sealed name, so a relabeled secret got wraps under
another secret's approvals.

protect_with_escrow and secret_add_with_escrow take the keys the user named
apart from the escrow keys a command appends. protect stages the named keys in
memory while it validates the rule and the sealing commit, records them after
validation and before either ref moves, and a refusal leaves record, refs and
oplog alone. secret add records the named keys before its ref moves. The CLI
no longer records after the operation landed.

The record is written with atomic_write_durable (fsynced temp file, rename,
fsynced directory), as durable as the ref write. rewrap reads the record only
for an entry that mints a wrap: a secret that opens, a path re-sealed or
rotated, or a target with no wrap yet. A randomized path whose every wrap is
reused copies them and needs no approval.

The refusal text says what is true: no ref moved and no approval was recorded.
sc protect --list, sc secret list, sc branch list and sc policy accept/forget
print repository text through sanitize_display_line.
…nc unchanged records

protect no longer stages approvals on the Repo handle. snapshot_files_with
takes the approval source as a parameter and protect passes the keys it is
about to record for that call only, so no other operation on the same handle
can see them. snapshot_files keeps its signature and reads the record.

secret grant refuses a registry entry sealed under another name before it
records an approval or wraps anything, as rotate and rewrap do.

rewrap checks a path re-seal against the record only after the ciphertext has
opened, so a corrupt blob is skipped as that when the record is unreadable.

An accept or forget that changes nothing still fsyncs .sc, so a retry after a
failed directory sync cannot report success on an unsynced record.
…orization, lock the record

secret grant opens the secret with the identity before it records or wraps
anything. The registry key and the name in the secret's metadata are both
repository data and can be made to agree, but the AEAD binds the name the secret
was sealed under, so an edited name fails to open and the grant is refused.

grant, secret grant and secret rotate --to record the named key only after the
identity is authorized and the operation validated, still before the ref moves.
secret_rotate_with takes the named keys as call-local approvals, and the CLI
passes them instead of recording first, so a refused command leaves no approval.

accept and forget read, change and write the record under .sc/index.lock, so
callers on one handle cannot lose each other's change.

ADR-0059 records the declined residual: an interruption after the approval write
and before the ref move leaves an approval for a key the user named on that
command.
@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: 94a7e3c5-fd2e-4255-bf3b-08b917436e3a
  • 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-20T11:43:20.267558Z 8ec36df PR opened
🔒 Security Review ✅ Completed 2026-11-20T11:47:35.049454Z 8ec36df 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: design by Mythos and reviewed by Sol; implementation reviewed with sol-loop (5 rounds, approved) and a Mythos security review; all checks green; Codex review has no findings.

@tonibergholm-codento
tonibergholm-codento merged commit ced3802 into main Nov 20, 2026
11 checks passed
@tonibergholm-codento
tonibergholm-codento deleted the fix/accepted-recipients branch November 20, 2026 11:54
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