Repository navigation
docs(stack-encrypt): ADR-0014, operations read the plaintext and at most one takes it - #1739
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
|
90ea9a6 to
af09109
Compare
1792653 to
2c7f3f7
Compare
af09109 to
fcd6c2c
Compare
1ad2a83 to
0c4ca60
Compare
3d55934 to
7b86835
Compare
92a4245 to
1a2d48d
Compare
…and at most one takes it A declaration's plaintext is copied wherever an operation that takes the value runs over a borrow, or two operations share one owned value. Three implementations do it, and the default owned form gives the first to every target that writes only the borrowed form. The same copy has been found in review three times, in JsonDocument, JsonTreeDocument and the storage-only EQL types. The ADR proposes the design for #1734. An operation is a reader, built from a reference, or a taker, built from the value. A declaration has any number of readers and at most one taker, which runs last, and the compiler checks it, as axum checks the order of a handler's extractors. No implementation clones. Vitamin C 0.10's EncryptRef makes sealing a reader, so the usual declaration has no taker at all. The status is proposed. The ADR lists four questions for a prototype to answer before it is accepted.
1a2d48d to
f233efa
Compare
cipherstash-agent
left a comment
There was a problem hiding this comment.
Review attestation
Reviewed f233efa · posted from Claude Code (scheduled routine) · claude-opus-5-5 · effort medium
Sources: code-review · claude-opus-5-5; mattpocock code-review (Standards, Spec) · claude-opus-5-5; rust-security · claude-opus-5-5
Skills: code-review, mattpocock-skills:code-review, rust-security, review-cross-check, review-post
Findings (9): 5 major, 4 minor. 9 inline, 0 below, 0 in reply.
Every finding was verified at f233efa and cross-checked against the existing feedback on this PR. None was already raised. Three candidate findings were refuted and are not posted: the claim that order terms cannot read by reference (vitaminc-ore implements Orderable for references), the frontmatter key extends: (ADR-0011 to 0013 use it), and the scope of the proposed test (it matches #1734).
One question is left open and not posted as a finding: Index::operation is bound on M: ConsumeSource (target/index.rs:272). Removing ConsumeSource for Borrowed therefore changes the public Index trait too, and the breaking-change list at line 221 does not mention it.
Generated by Claude Code
…ttle its conflicts The first version of ADR-0014 and #1737 answer #1734 two ways. The ADR inferred each operation's role from its type through a marker parameter. #1737 uses position: `zip` takes a borrowed description as its argument and runs it first, so only the operation written first is handed an owned value. The review of the ADR reports that the inferred form is ambiguous for two readers. This revision adopts #1737's mechanism and settles each point where the two disagreed: - `passthrough` is the only taker, and a borrowed `passthrough` keeps its copy of a value stored in the clear, as ADR-0012 requires; - the named copy adapter is dropped; - whoever is handed an owned value wipes it on every path, which closes a gap in the public operations on `next`; - queries and their checks are readers; - the claim of one copy is scoped to the typed path, and the dynamic interface's count is stated; - `Date`, `Timestamp`, `Decimal`, `sem::Orderable` and `op::Ordered` are removed, and an order index is bounded by Vitamin C's `Orderable`, which does not cover bytes. That is the typed half of #1611. It also records the order in which #1737, the order bound and #1611 land, and defines "reader" and "taker" in CONTEXT.md. Refs #1734, #1737, #1611.
… from bytes Dan confirmed the revision's three choices on 22 November 2026, so the status is `accepted`. - A borrowed `passthrough` keeps its copy. The ADR now says when the copy happens (a whole record run from a borrow, to keep the plaintext) and what removing it would cost: a caller who needs the plaintext afterwards would clone the whole value, its secrets included. - `Owned` mode requires `Zeroize`, as written. - Stack Encrypt no longer derives an order term from bytes. The keyset's term functions take a `Vec<u8>` on `next` only because `sem::Orderable` covers it, and that trait is removed. No ordering operator compares bytes, and a stored row with such a term still opens. This was left open for #1611 and is now decided. Refs #1734, #1737, #1611.
Summary
Stack Encrypt (
packages/stack-encrypt) is the Rust engine every CipherStash language SDK runs on. When it encrypts a value, it often holds two or three copies of the plaintext in memory while it works. Each copy is wiped afterwards, so nothing leaks, but each one is an extra place the plaintext sits and an extra wipe that has to be right. Review has found the same copy three times, in three different types.This pull request adds an architecture decision record (ADR), ADR-0014, with the design that removes those copies. It changes no code. It is the design for #1734, which asks that no plaintext is ever copied.
Revised and accepted on 22 November 2026. The first version and #1737 answered #1734 two ways. The revision adopts #1737's mechanism, settles each point where the two disagreed, and says how #1737 and #1611 land.
Changes
packages/stack-encrypt/docs/adr/0014-operations-read-the-plaintext-and-at-most-one-takes-it.md, statusaccepted.packages/stack-encrypt/CONTEXT.mddefines reader and taker.The decision in short:
passthrough, a field stored in the clear, is the only one.first.zip(second)always lends the value tosecond, runs it first, and returns the outputs in the order written.Clone. A borrowedpassthroughstill copies its value, which is stored in the clear.Orderable. Stack Encrypt's ownDate,TimestampandDecimal, and itssem::Orderableandop::Ordered, are removed.What the revision settles
zip, as #1737 implements itpassthroughCloneon a value stored in the clear (ADR-0012)Ownedmode requiresZeroizeThe order of work is in the ADR's "How the work lands": #1737 first, then the order bound (item 4 of #1734), then #1611 rebased on top with its typed-bound commits dropped.
Verification
Docs only: no code, test or fixture changes. I checked each fact the ADR states:
next: the two implementations that copy (ConsumeSource for Borrowed,ShareSource for Ownedintarget/source.rs), the default owned form, the operations that take the value, and the typessem::Orderableandop::Orderedlist.fc3a506c7):Sourceand the two modes intarget/source.rs,zipand the leaf operations intarget/operations.rs, the bound ofIndex::operation, the default owned form, and thatConsumeSource for Borrowedis the onlyClonebound on a plaintext left.ddb18a91d): that it moves each order bound fromsem::Orderabletoop::Ordered, and what else it changes.EncryptRef,SchemeVisitor, and which typesvitaminc-ore'sOrderablecovers. It covers Vitamin C's date, timestamp and decimal and a reference to each, and it does not cover bytes or an 8-bit integer.Not verified by me: the claim that the marker form is ambiguous for two readers is the reviewer's, from a prototype. The test results the ADR cites for #1737 are the ones #1737 reports.
Related
Refs #1734, #1737, #1611. Builds on #1687 (merged).
Review notes
Dan confirmed these three choices on 22 November 2026:
passthroughkeepsClone. The copy happens only when a caller runs a whole record from a borrow to keep the plaintext. Removing it would make that caller clone the whole value, secrets included.Ownedmode requiresZeroize. This closes a gap that is onnexttoday: the publicciphertextoperation drops a refused owned value without wiping it. It is new work for refactor(stack-encrypt,eql-bindings)!: read every plaintext by reference #1737.The work for #1737 and #1611 is in the ADR's "How the work lands" section.