Skip to content

docs(stack-encrypt): ADR-0014, operations read the plaintext and at most one takes it - #1739

Merged
coderdan merged 3 commits into
nextfrom
docs/stack-encrypt-adr-readers-and-one-taker
Nov 22, 2026
Merged

coderdan merged 3 commits into
nextfrom
docs/stack-encrypt-adr-readers-and-one-taker

Conversation

@coderdan

@coderdan coderdan commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

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, status accepted.
  • packages/stack-encrypt/CONTEXT.md defines reader and taker.

The decision in short:

  • An operation that seals a value or derives a search term reads the plaintext through a reference. It is a reader.
  • An operation whose output is the plaintext itself is a taker. passthrough, a field stored in the clear, is the only one.
  • A declaration has any number of readers, and at most one operation is handed the value. The compiler checks this by position: first.zip(second) always lends the value to second, runs it first, and returns the outputs in the order written.
  • No implementation copies a plaintext that is sealed or indexed, so a plaintext type does not need Clone. A borrowed passthrough still copies its value, which is stored in the clear.
  • Whoever is handed the value wipes it on every path, including a refused context.
  • An order index is bounded by Vitamin C's Orderable. Stack Encrypt's own Date, Timestamp and Decimal, and its sem::Orderable and op::Ordered, are removed.

What the revision settles

Point First version Now
How the one taker is checked Inferred from each operation's type, through a marker Position in zip, as #1737 implements it
Borrowed passthrough Removed Kept, with Clone on a value stored in the clear (ADR-0012)
A named adapter that copies Proposed Dropped
Wiping an owned value Stated, with no mechanism The operation handed the value wipes it, and Owned mode requires Zeroize
Queries and their checks Not covered Readers
The dynamic interface "A write holds one copy" One decoded frame for each field, and no further copy
The order traits "Can be removed" Removed, and the bound is Vitamin C's
An order term of bytes Not covered Removed: the keyset's term functions no longer take bytes

The 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:

  • On next: the two implementations that copy (ConsumeSource for Borrowed, ShareSource for Owned in target/source.rs), the default owned form, the operations that take the value, and the types sem::Orderable and op::Ordered list.
  • On refactor(stack-encrypt,eql-bindings)!: read every plaintext by reference #1737 (fc3a506c7): Source and the two modes in target/source.rs, zip and the leaf operations in target/operations.rs, the bound of Index::operation, the default owned form, and that ConsumeSource for Borrowed is the only Clone bound on a plaintext left.
  • On fix(stack-encrypt)!: a data plan refuses an order index on bytes #1611 (ddb18a91d): that it moves each order bound from sem::Orderable to op::Ordered, and what else it changes.
  • In the published sources of Vitamin C 0.10.0: EncryptRef, SchemeVisitor, and which types vitaminc-ore's Orderable covers. 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:

  1. Borrowed passthrough keeps Clone. 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.
  2. Owned mode requires Zeroize. This closes a gap that is on next today: the public ciphertext operation drops a refused owned value without wiping it. It is new work for refactor(stack-encrypt,eql-bindings)!: read every plaintext by reference #1737.
  3. The order bound lands before fix(stack-encrypt)!: a data plan refuses an order index on bytes #1611, and Stack Encrypt stops deriving an order term from bytes. No ordering operator compares bytes, and a stored row that carries such a term still opens.

The work for #1737 and #1611 is in the ADR's "How the work lands" section.

@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI; Enforced overrides: Organization
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2822a425-a774-4a56-a9c3-9a09425fec30

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

@changeset-bot

changeset-bot Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: ed8569e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderdan
coderdan force-pushed the feat/stack-encrypt-typed-json-queries branch from 90ea9a6 to af09109 Compare November 21, 2026 08:46
@coderdan
coderdan force-pushed the docs/stack-encrypt-adr-readers-and-one-taker branch from 1792653 to 2c7f3f7 Compare November 21, 2026 08:46
@coderdan
coderdan force-pushed the feat/stack-encrypt-typed-json-queries branch from af09109 to fcd6c2c Compare November 21, 2026 09:02
@coderdan
coderdan force-pushed the docs/stack-encrypt-adr-readers-and-one-taker branch 2 times, most recently from 1ad2a83 to 0c4ca60 Compare November 21, 2026 09:36
@coderdan
coderdan force-pushed the feat/stack-encrypt-typed-json-queries branch from 3d55934 to 7b86835 Compare November 21, 2026 10:37
@coderdan
coderdan force-pushed the docs/stack-encrypt-adr-readers-and-one-taker branch 3 times, most recently from 92a4245 to 1a2d48d Compare November 21, 2026 16:18
…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.
@coderdan
coderdan force-pushed the docs/stack-encrypt-adr-readers-and-one-taker branch from 1a2d48d to f233efa Compare November 22, 2026 01:30
Base automatically changed from feat/stack-encrypt-typed-json-queries to next November 22, 2026 02:32

@coderdan coderdan left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ADR Approved.

@coderdan
coderdan marked this pull request as ready for review November 22, 2026 03:27
@coderdan
coderdan requested a review from a team as a code owner November 22, 2026 03:27

@cipherstash-agent cipherstash-agent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.
@coderdan coderdan changed the title docs(stack-encrypt): propose ADR-0014, operations read the plaintext and at most one takes it docs(stack-encrypt): ADR-0014, operations read the plaintext and at most one takes it Nov 22, 2026
… 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.
@coderdan
coderdan merged commit 96e7242 into next Nov 22, 2026
31 checks passed
@coderdan
coderdan deleted the docs/stack-encrypt-adr-readers-and-one-taker branch November 22, 2026 04:38
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