Repository navigation
Description
Background
Stack Encrypt (packages/stack-encrypt) is the Rust encryption engine that every CipherStash SDK runs on. Decrypting an OpaqueBlob<T> turns the decrypted bytes back into a Rust value with serde.
A blob can be a valid ciphertext of a different shape from T, so the read fails part-way. Since #1676 (PR #1750), stack-encrypt reads the bytes "in place" into a blank T::default() that is wiped if the read fails part-way. So for an ordinary derived struct, every field read before the failure is wiped.
Problem
serde still builds some values in a temporary of its own, and stores them in T only once they are complete. If the read fails inside one of them, the pieces already built are freed without being wiped, and those pieces can hold decrypted text. This happens for:
- an element of a
Vecor other sequence, a map entry, anOption, aBox, and an enum; - a field read with
#[serde(deserialize_with)]or#[serde(with)]; - a struct marked
#[serde(transparent)],fromortry_from, one with a#[serde(flatten)]field, and one whose every field usesdeserialize_with. serde reads these whole wherever they appear, so whenTitself is one of them, nothing is wiped; - a type with a hand-written
Deserializethat does not implementdeserialize_in_place.
Separately, serde reserves room for at most 1 MiB of a sequence's elements up front. A longer sequence grows its buffer while reading, and each old buffer is freed unwiped, even when decryption succeeds. Integers and other inline values are left in those old buffers.
The lifecycle conformance profile records all of this as the native-partial-decode-inside-whole-values known gap. It is pinned by two failing-on-purpose heap tests in packages/stack-encrypt/tests/heap_hygiene.rs.
Proposal
-
For each case, decide whether stack-encrypt can close it. Some options:
- an in-place read of
OptionorBoxwhen the inner type isDefault; - an element seed that wipes a part-built element;
- refusing the unsupported derive shapes at compile time.
Otherwise, keep it as a documented limit that the caller handles with parts that wipe themselves on drop (
Zeroizing<String>,ZeroizeOnDrop). - an in-place read of
-
For the 1 MiB regrowth, look at a fix in serde or in Vitamin C's storage reader, or an opt-in wiping sequence type.
-
This is done when every case is closed, with its negative control turned into passing evidence, or is kept as a documented limit with the reason written in the lifecycle contract.
Activity