Repository navigation
fix(stack-encrypt): wipe the fields a refused OpaqueBlob read before the refusal - #1750
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
|
Mutation testing (cargo-mutants,
|
| caught | missed | unviable | timeout |
|---|---|---|---|
| 1 | 0 | 1 | 0 |
Every mutant in the changed lines was caught by a test.
There was a problem hiding this comment.
🟡 Changes recommended
The plaintext-wiping guarantee overstates coverage for derived Serde structs that fall back to whole-value decoding, requiring qualified documentation and a negative-control test.
1 open issue
What changed in this PR
This PR narrows the partial-decoding cleanup gap in Stack Encrypt’s Rust OpaqueBlob<T> support, addressing #1676 by wiping fields already stored when a later field is refused.
Changes:
- Decode into a guarded
T::default()using Serde’s in-place reader. - Add heap checks and a wipe-witness test, and enroll them in lifecycle conformance.
- Document the new
Defaultrequirement and remaining cleanup limits.
| File | Description |
|---|---|
packages/stack-encrypt/tests/ui/opaque_blob_requires_zeroize.stderr |
Refreshes the diagnostic’s decode bound. |
packages/stack-encrypt/tests/opaque_blob.rs |
Adds a partial-read wipe witness and defaultable fixtures. |
packages/stack-encrypt/tests/heap_hygiene.rs |
Checks partial-read cleanup and the remaining sequence-element gap. |
packages/stack-encrypt/tests/exchange_conformance.rs |
Makes the blob fixture defaultable. |
packages/stack-encrypt/src/lib.rs |
Updates the documentation example’s derives. |
packages/stack-encrypt/src/blob.rs |
Adds guarded in-place decoding and cleanup documentation. |
packages/stack-encrypt/fuzz/Cargo.lock |
Records the direct serde_derive dependency. |
packages/stack-encrypt/examples/opaque_blob.rs |
Adapts example types to the Default requirement. |
packages/stack-encrypt/docs/adr/0011-a-whole-value-is-one-storage-blob-sealed-as-one-leaf.md |
Records the cleanup approach and remaining limits. |
packages/stack-encrypt/CHANGELOG.md |
Explains the behavior change and upgrade steps. |
packages/stack-encrypt/Cargo.toml |
Enables Serde’s in-place derive feature. |
packages/eql/Cargo.lock |
Records the dependency for the EQL workspace. |
languages/golang/encrypt/guest/Cargo.lock |
Records the dependency for the Go encryption guest. |
conformance/stack-encrypt/v1/lifecycle-v1.enrollment.json |
Enrolls cleanup tests and renames the known gap. |
conformance/stack-encrypt/lifecycle-contract.md |
Updates cleanup coverage and its limitations. |
Cargo.lock |
Records the dependency for the root workspace. |
Review effort: Balanced
cipherstash-agent
left a comment
There was a problem hiding this comment.
Review attestation
Reviewed aafa693 · posted from Claude Code (scheduled routine) · claude-opus-5-5 · code-review effort medium
Sources: code-review · claude-opus-5-5; rust-security agent · claude-opus-5-5; mattpocock code-review (standards, spec) · claude-opus-5-5
Skills: code-review, company-skills:rust-security, mattpocock-skills:code-review, company-skills:review-cross-check, company-skills:review-post
Findings (11): 1 major, 10 minor. 10 are inline and 1 is below. Every finding was checked against the code at aafa693 with a repro or a trace. Two were refuted and are not posted: the lifecycle-contract.md:16 wording, and the ADR-0011 amendment marker.
docs/plans/2026-10-24-stack-encrypt-api-plan.md:2148(outside diff) minor This still says "Issue #1676 is open for the partial Serde decode". Record the struct-field case as done, and name the remainingnative-partial-decode-inside-whole-valuesgap and its tracking issue.
Generated by Claude Code
a98951b to
f8d29e9
Compare
…the refusal A valid blob of another shape can be refused after a derived Deserialize has read some of its fields. serde holds those fields as locals until the whole T is built, so a refusal dropped them as ordinary values, unwiped: the lifecycle profile carried this as the native-partial-decode-fields known gap. Decrypting an OpaqueBlob<T> now reads the blob in place, through serde's Deserialize::deserialize_in_place, into a T::default() held in a Zeroizing<T>. A derived Deserialize for a struct stores each field in that value as it reads it, so a refusal drops the Zeroizing and wipes every field read before it: the fields of the struct, of structs nested in it, and the elements of a Vec stored before the refusal. This needs serde_derive's deserialize_in_place feature, which stack-encrypt now turns on (Cargo unifies it across the build; deserialize itself is unchanged), and a T: Default bound on decrypting a blob. OpaqueBlob is unreleased, so the bound changes no released API. serde still builds an element of a sequence, a map entry, an Option, a Box and an enum whole. A refusal inside one of those drops what it built unwiped. The lifecycle profile now enrolls the closed case as lifecycle-partial-output-v1 evidence (two heap observations and a drop witness) and carries the rest as the narrower native-partial-decode-inside-whole-values known gap, with its own should_panic negative control in place of the old one. eql-bindings needs no change: it decodes no plaintext through Serde. Its JSON plaintext goes through stack-encrypt's own JSON parser, which already wipes a part-built document. Closes #1676
serde_derive writes no deserialize_in_place for a struct marked transparent, from or try_from, one with a flatten field, or one whose every field uses deserialize_with. Such a struct is read whole wherever it appears, so a refusal of its later field drops the fields read before it unwiped, even when it is T itself. The blob docs, ADR-0011, the CHANGELOG and the lifecycle contract now list those shapes, and a field read with deserialize_with, among the values serde reads whole, in place of the wording "a type whose Deserialize is not derived for a struct" (String, Vec, tuples and arrays are read in place). A second should_panic control opens a blob as a transparent struct, and the native-partial-decode-inside-whole-values enrollment names every case, lists both controls and carries a tracking placeholder for the follow-up issue. The promise for the elements of a sequence is qualified: serde reserves room for at most 1 MiB of elements before it reads them, and a longer sequence regrows its buffer and frees each old one unwiped. A field serde skips when reading keeps the value T::default() gives it, because the in-place read never assigns it, so a #[serde(default = "...")] on it is not used. The docs say so, and a test pins it against serde's whole-value read of the same bytes. A tests/ui case decrypts and decodes a type that is Zeroize but not Default, so relaxing the bound, and with it the in-place wipe, fails a test. a_field_read_before_a_refusal_is_wiped encrypted a Witness, which moved WITNESS_WIPES while is_wiped_on_drop_and_into_inner_keeps_it_guarded checked exact deltas of it, so threaded cargo test failed now and then (7 of 200 runs). It encrypts a Tracked source now: 0 of 200. serde_derive comes from [workspace.dependencies]; stack-encrypt turns on deserialize_in_place there. The heap tests share a Sealed struct and one is_a_mismatch assertion. The API plan records the closed case and the gap that remains.
aafa693 to
375e611
Compare
|
Review round 1, addressed in 375e611. The branch was also rebased onto #1749's new head and force-pushed.
Checks at 375e611:
|
There was a problem hiding this comment.
🔵 Needs a closer look
The proposed Default bound for blob decryption, skipped-field default changes, and build-wide serde_derive deserialize_in_place feature require maintainer judgment on API and dependency trade-offs.
No open issues 🎉
1 resolved since last review
Review effort: Balanced
coderdan
left a comment
There was a problem hiding this comment.
Human pass. LGTM!

Summary
Decrypting an
OpaqueBlob<T>can fail part-way. A blob can be a valid ciphertext of the wrong shape: a later field is missing or has the wrong type, and it's refused after some fields were already decrypted and read. Those fields used to be freed with the plaintext still in them. Decrypting now reads the blob into aT::default()that is wiped if the blob is refused, so the fields read before the refusal are wiped too.Two costs need your decision:
T: Default.OpaqueBlobis unreleased, so this breaks nothing that has shipped.deserialize_in_placefeature. Cargo applies a feature to the whole build, so every#[derive(Deserialize)]in a build that includes stack-encrypt also generates that method.deserializeitself is unchanged.Changes
src/blob.rs:OpaqueBlob::decodereads through a privateReadInPlace<T>, which callsT::deserialize_in_placeon aZeroizing::new(T::default()).T: Default.#[serde(skip)]field keepsT::default()'s value.Cargo.toml:serde_deriveis now a root[workspace.dependencies]entry, and stack-encrypt uses it withfeatures = ["deserialize_in_place"]. A comment explains why, and acargo-udepsignore covers it because no code names the crate.packages/eql,stack-encrypt/fuzz): oneserde_deriveline each.heap_hygiene.rs: theshould_paniccontrol for this gap becomesopaque_blob::given_a_blob_refused_after_fields_are_built, with two real heap assertions and one new control for the narrower gap that remains.opaque_blob.rs: a drop-witness test,a_field_read_before_a_refusal_is_wiped, that runs on every platform.#[derive(Default)]on the blob types the tests, example and docs decrypt.opaque_blob_requires_zeroize.stderris refreshed; only the bound line changes.lifecycle-partial-output-v1now enrolls the two heap tests and the drop witness.native-partial-decode-fieldsis replaced by the narrowernative-partial-decode-inside-whole-values.Verification
the_fields_built_before_it_are_wiped: 3 heap blocks freed with plaintext still in them.a_nested_field_and_whole_elements_built_before_it_are_wiped: 4 blocks.a_field_read_before_a_refusal_is_wiped: the value"secret"is never wiped.String.cargo test -p stack-encrypt --all-features: all test targets and doc tests pass.cargo fmt --check: clean.cargo clippywith-D warnings: clean for stack-encrypt and for the whole root workspace with--locked, which checks every derive with the new feature on.cargo docwith-D warnings: clean.cargo test --locked -p eql-encryption-tests --all-featurespasses.scripts/__tests__/stack-lifecycle-conformance.test.mjs: passes.go test ./...passes, andgo generate ./...produces no drift.--in-diff: of the two mutants, one is caught and the other doesn't compile.Related
Closes #1676. Stacked on #1749.
The cases this PR can't reach are tracked in #1754: values serde builds whole (sequence elements, map entries,
Option,Box, enums), the derive shapes it doesn't read in place, and the 1 MiB sequence regrowth.Review notes
Why read in place: a type's derived
Deserializeholds the fields it has read as locals and drops them on an error, where nothing outside the type can reach them. Reading in place is the only mechanism that puts those fields where the library can wipe them. Serde documentsdeserialize_in_placeas stable public API, although it is hidden from rustdoc.Now covered: fields of the struct, fields of nested structs, tuples and arrays, and
Vecelements stored before the refusal.Still a known gap (
native-partial-decode-inside-whole-values, tracked in stack-encrypt: wipe what serde reads whole when an OpaqueBlob decrypt is refused #1754):Option, aBoxor an enum;deserialize_withorwith;transparent,fromortry_from, has aflattenfield, or hasdeserialize_withon every field;Deserializewithoutdeserialize_in_place;Negative controls pin both the whole-value case and the
transparentcase. The workaround is unchanged: a field type that wipes itself on drop, such asZeroizing<String>.One change on success: a field that serde skips keeps
T::default()'s value, so a#[serde(default = "...")]on it isn't used. This is documented and pinned by a test (given_a_field_serde_skips). Atests/uicase pins the newT: Defaultbound.eql-bindings needs no change: it never decodes plaintext through Serde, and its JSON plaintext goes through stack-encrypt's own parser, which already wipes a part-built document.