Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ rustls = { version = "0.23", default-features = false, features = ["std", "tls12
rustls-platform-verifier = "0.6"
rustls-webpki = { version = "0.103", default-features = false, features = ["alloc"] }
serde = { version = "1.0", features = ["derive"] }
# Named on its own only so a crate can turn on one of its features.
# stack-encrypt turns on `deserialize_in_place`, which every derive in the
# build then writes.
serde_derive = "1.0"
serde_json = { version = "1.0.132" }
# Constant-time hex (through base16ct) for serde over the order terms.
serdect = { version = "0.3", default-features = false, features = ["alloc"] }
Expand Down
37 changes: 26 additions & 11 deletions conformance/stack-encrypt/lifecycle-contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ process. Python and TypeScript are explicitly not enrolled.
|---|---|---|
| `lifecycle-ownership-v1` | Actual record operations and owned `Vec<S>` to `Vec<T>` conversions release fulfilment captures exactly once on success, provider failure and unpolled drop; an unpolled encrypt or decrypt makes no key request. Zipped fulfilments do not share key material. An owned `OpaqueBlob` source is wiped before its pending is returned, on success and on an encoding refusal. A decrypted `OpaqueBlob<T>` is wiped once on drop, and the `Zeroizing<T>` its `into_inner` returns is wiped once when it is dropped, not before. | Client keys are consumed/redacted; explicit close and unreachable-client cleanup release guest memory; calls on a closed client fail. GC cleanup is eventual, so callers should close explicitly. |
| `lifecycle-cancellation-v1` | Dropping an encrypt future paused in key generation, or a decrypt future paused in key retrieval, drops the provider future and operation captures, for a record operation or an owned collection; subsequent work on the cipher succeeds. Guest ABI abort spends the handle and drops the operation. | Cancellation before a call sends no request; cancellation between steps or during token fetch leaves unrelated operations usable. A guest step that overruns cancellation closes the client. Discarded late output is wiped. |
| `lifecycle-partial-output-v1` | A batch with a valid first row and a later authenticated type mismatch releases its decoded prefix without marked heap residue. Tests check this for the dynamic record path and for the owned `Vec<Ciphertext>` to `Vec<String>` conversion. For owned collections, drop witnesses are test values that record whether they were wiped. They show that the prefix is wiped, not leaked, after a late failure or an element's panic. The same holds for a column that is a field of a record. For an owned record, a drop witness shows that a field opened before a later field is refused is wiped. Existing context cases reject late authentication failures without returning partial output. An `OpaqueBlob` refused before its first field is built leaves no marked residue; a refusal after some fields are built is the `native-partial-decode-fields` limit below. | Generated and raw batch APIs return no partial rows on failure; interrupted HTTP bodies fail; cancelled output is wiped. SDK conversion diagnostics contain no decrypted values. This does not assert erasure of partially populated caller-owned Go objects. |
| `lifecycle-partial-output-v1` | A batch with a valid first row and a later authenticated type mismatch releases its decoded prefix without marked heap residue. Tests check this for the dynamic record path and for the owned `Vec<Ciphertext>` to `Vec<String>` conversion. For owned collections, drop witnesses are test values that record whether they were wiped. They show that the prefix is wiped, not leaked, after a late failure or an element's panic. The same holds for a column that is a field of a record. For an owned record, a drop witness shows that a field opened before a later field is refused is wiped. Existing context cases reject late authentication failures without returning partial output. An `OpaqueBlob` refused before its first field is built leaves no marked residue. One refused after some fields are built leaves none either, for a derived struct serde reads in place: the blob is read into a `T::default()` that the refusal wipes. The heap observer checks this for the fields of a struct, the fields of a struct nested in it, and the elements of a sequence stored before the refusal (up to the 1 MiB of elements serde reserves before reading a sequence). A drop witness shows that a field read before a missing field is wiped once. A refusal inside a value serde builds whole is the `native-partial-decode-inside-whole-values` limit below. | Generated and raw batch APIs return no partial rows on failure; interrupted HTTP bodies fail; cancelled output is wiped. SDK conversion diagnostics contain no decrypted values. This does not assert erasure of partially populated caller-owned Go objects. |
| `lifecycle-buffer-cleanup-v1` | The existing allocator observer checks selected write/read/JSON parse paths and has a negative control. It also checks an `OpaqueBlob`'s encoded buffer (which regrows while it holds plaintext), its planned leaf and its opened buffer, and for those blob paths that no marked block allocated during the operation is still live at its end (a leak the free-time scan cannot see), with its own negative control. The partial-decode limit is pinned separately and is not enrolled here (see below). One of those paths encrypts an owned `Vec<String>` collection through its guard. Drop witnesses show that an owned collection's source is wiped before its pending request is returned. That includes a refused context, and a context conversion that panics. It also includes the elements after an element whose declaration panics. For an owned record, drop witnesses show that the record wipes the fields it seals, also when the context is refused. When a context is refused, no copy of a sealed plaintext is dropped unwiped. Witnesses check this for a `struct` record, a nested record, a `plaintext` record, a record with a stored context, a column, a `StackCipherText`, a `Vec<StackCipherText>`, and an `Encrypted<Terms>`. They also show that the record moves its passthrough fields without copying them, and that a record decrypted into a `Protected` is wiped when the `Protected` is dropped. Guest ABI tests check buffer-registry cleanup, error-buffer release and protected text drop. | Request bodies survive until their owner closes them, then wipe; refused requests wipe; heap growth wipes abandoned backing arrays; guest runtime close releases memory. Post-encryption memory scans are supplementary observations. |
| `lifecycle-diagnostics-v1` | Guest errors discard untrusted foreign cause messages; failed/successful exports do not hand over stale diagnostics. | Structured errors remain available after failures; SDK errors and redacted display/logging expose types or fields rather than plaintext values. |
| `lifecycle-validation-before-io-v1` | Existing runtime/read/context cases count provider calls. Wrong shape, independently detectable context mismatch and oversized descriptors fail before key I/O; lazy assembly stops after local failure. An `OpaqueBlob` whose `Serialize` refuses requests no key, and an oversized context is refused before the value is encoded; on decrypt the leaf authenticates (one retrieval) before any blob byte is read, and tampering is `Aead` however the bytes would decode. | Host refusals happen before entering the guest, and shared runtime/read cases exercise the uninitialised guest's preflight boundary. Go does not yet expose native provider counters. |
Expand Down Expand Up @@ -53,16 +53,31 @@ These entries in the index are limitations, not successful requirements:
decrypted plaintext can remain in the WASM shadow stack in underlying cipher
temporaries. It is not enrolled as passing evidence. The post-encryption scan
cannot establish the post-decryption guarantee.
- **`native-partial-decode-fields` — known gap.**
`opaque_blob::a_partial_decode_drops_the_fields_it_built_unwiped` in
`packages/stack-encrypt/tests/heap_hygiene.rs` is a `should_panic` negative
control: a derived `Deserialize` that has built a `String` field of an
`OpaqueBlob<T>` and then refuses a later field drops that field as an
ordinary value, unwiped, because no `T` was constructed to wipe. The opened
buffer the fields were copied from is wiped. This is serde's construction
order, stated in the `blob` module docs; a `T` whose fields wipe on drop
closes it for those fields. It is enrolled as the observation of a limit,
not as passing cleanup evidence.
- **`native-partial-decode-inside-whole-values` — known gap.**
`opaque_blob::given_a_blob_refused_after_fields_are_built::a_refusal_inside_a_sequence_element_drops_what_the_element_built`
in `packages/stack-encrypt/tests/heap_hygiene.rs` is a `should_panic`
negative control, and so is
`opaque_blob::given_a_blob_refused_after_fields_are_built::a_refusal_in_a_struct_the_derive_reads_whole_drops_its_fields`.
An `OpaqueBlob<T>` is read in place, so for most derived structs the
fields are wiped when a later field is refused. serde builds some values
whole and stores them only when they are complete: an element of a
sequence, a map, an `Option`, a `Box`, an enum, a field read with
`deserialize_with`, and a type whose own `Deserialize` impl writes no
`deserialize_in_place`. The derive writes none for a struct marked
`#[serde(transparent)]`, `from` or `try_from`, one with a
`#[serde(flatten)]` field, or one whose every field uses
`deserialize_with`, so such a struct is built whole wherever it appears,
`T` included. A refusal inside any of these drops the parts of it already
built as ordinary values, unwiped. The first control refuses a field of a
sequence's first element after the element's `String` field is built;
the second refuses a later field of a struct a `transparent` wrapper reads
whole. Separately, serde reserves room for at most 1 MiB of a sequence's
elements before reading them, and a longer sequence regrows its buffer
and frees each old one unwiped. The enrollment names each case and the
issue that tracks them (#1754). The opened buffer the parts were copied
from is wiped. The `blob` module docs state this; a part that wipes
itself on drop closes it for that part. It is enrolled as the observation
of a limit, not as passing cleanup evidence.
- **`native-heap-observer-exclusions` — limited observation.**
`packages/stack-encrypt/tests/heap_hygiene.rs` watches marked frees on the
executing thread. Its existing observer excludes a named upstream aws-lc
Expand Down
28 changes: 26 additions & 2 deletions conformance/stack-encrypt/v1/lifecycle-v1.enrollment.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@
"a_late_read_type_failure_leaves_no_plaintext_on_the_heap",
"a_late_type_failure_in_an_owned_column_leaves_no_plaintext_on_the_heap",
"opaque_blob::an_opaque_blob_of_another_shape_leaves_no_plaintext_on_the_heap",
"opaque_blob::given_a_blob_refused_after_fields_are_built::the_fields_built_before_it_are_wiped",
"opaque_blob::given_a_blob_refused_after_fields_are_built::a_nested_field_and_whole_elements_built_before_it_are_wiped",
"json_plaintext::text_that_is_not_a_document_leaves_no_plaintext_on_the_heap"
],
"collections": [
Expand All @@ -174,6 +176,9 @@
"owned-records": [
"a_field_opened_before_a_later_field_is_refused_is_wiped"
],
"opaque": [
"given_a_decrypted_blob::a_field_read_before_a_refusal_is_wiped"
],
"contexts": ["shared_context_boundaries"],
"go": [
"TestContextBoundaries",
Expand Down Expand Up @@ -326,9 +331,28 @@
"evidence": "packages/stack-encrypt/tests/heap_hygiene.rs"
},
{
"id": "native-partial-decode-fields",
"id": "native-partial-decode-inside-whole-values",
"status": "known-gap",
"evidence": "packages/stack-encrypt/tests/heap_hygiene.rs::opaque_blob::a_partial_decode_drops_the_fields_it_built_unwiped"
"tracking": "#1754",
"cases": [
"sequence-element",
"map",
"option",
"box",
"enum",
"deserialize-with-field",
"serde-transparent-struct",
"serde-from-struct",
"serde-try-from-struct",
"serde-flatten-struct",
"all-fields-deserialize-with-struct",
"hand-written-deserialize-without-in-place",
"sequence-regrown-past-1-mib"
],
"evidence": [
"packages/stack-encrypt/tests/heap_hygiene.rs::opaque_blob::given_a_blob_refused_after_fields_are_built::a_refusal_inside_a_sequence_element_drops_what_the_element_built",
"packages/stack-encrypt/tests/heap_hygiene.rs::opaque_blob::given_a_blob_refused_after_fields_are_built::a_refusal_in_a_struct_the_derive_reads_whole_drops_its_fields"
]
},
{
"id": "caller-owned-host-values",
Expand Down
14 changes: 12 additions & 2 deletions docs/plans/2026-10-24-stack-encrypt-api-plan.md
Original file line number Diff line number Diff line change
Expand Up @@ -2146,8 +2146,18 @@ table.
when it is dropped.
- **Why.** Plaintext must not stay in freed memory.
- **Done already.** Collections wipe the values decoded before a failure.
Cancellation and drop are tested (#1493, #1501).
- **Tracked in.** Issue #1676 is open for the partial Serde decode, which pull request #1503 recorded as a known gap. Issue #1684 is open for the drop-wiping adapter for a single value, such as `Zeroizing<String>`, which needs Vitamin C to implement `FromScalar` for `Zeroizing<T>`. Issue #1458 is open: data keys by reference. Issues #1468 and #1480 are closed. Pull requests #1493, #1501 and #1503 are merged; a decrypted `OpaqueBlob<T>` wipes its value when it is dropped, and its `into_inner` returns a `Zeroizing<T>`.
Cancellation and drop are tested (#1493, #1501). A decrypted
`OpaqueBlob<T>` is read in place into a `T::default()`, so a refusal
wipes the fields of most derived structs that were read before it
(#1676, pull request #1750). Decrypting needs `T: Default`.
- **Tracked in.** Issue #1754 is open for what #1676 left: the
`native-partial-decode-inside-whole-values` known gap. serde still builds
some values whole (an element of a sequence, a map, an `Option`, a `Box`,
an enum, a field read with `deserialize_with`, and a struct marked
`transparent`, `from` or `try_from`, with a `flatten` field, or whose
every field uses `deserialize_with`), and a refusal inside one drops what
it built unwiped; a sequence longer than the 1 MiB serde reserves frees
each regrown buffer unwiped. Issue #1684 is open for the drop-wiping adapter for a single value, such as `Zeroizing<String>`, which needs Vitamin C to implement `FromScalar` for `Zeroizing<T>`. Issue #1458 is open: data keys by reference. Issues #1468 and #1480 are closed. Pull requests #1493, #1501 and #1503 are merged; a decrypted `OpaqueBlob<T>` wipes its value when it is dropped, and its `into_inner` returns a `Zeroizing<T>`.
- **Finished when** the conformance profile for the lifecycle covers both cases.

### 4. The query engine
Expand Down
1 change: 1 addition & 0 deletions languages/golang/encrypt/guest/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/eql/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 32 additions & 1 deletion packages/stack-encrypt/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -1209,7 +1209,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
key. Encrypt with `keyset.encrypt(OpaqueBlob::new(value))`, for any
`Serialize + Zeroize` value. Decrypt with
`keyset.decrypt::<OpaqueBlob<T>>(ct)`, for any
`DeserializeOwned + Zeroize` type, then call `into_inner()`.
`DeserializeOwned + Default + Zeroize` type, then call `into_inner()`.
- The value is encoded with version 1 of Vitamin C's storage profile
(`vitaminc_aead_frame::storage`). The encoded bytes start with a `VCS`
header and a version byte, inside the plaintext. The profile has a
Expand Down Expand Up @@ -1238,6 +1238,37 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
`Zeroizing<T>`, so the value is still wiped on drop after it leaves the
blob. `Zeroizing<T>` derefs to `T`. A decrypted scalar is still an ordinary owned value, and nothing
wipes it on drop.
- **A blob refused part-way through reading wipes the fields it read**
(#1676). A valid blob of another shape can be refused after some of its
fields are read, for example when a later field is missing or has another
type. Those fields used to be dropped unwiped, because serde holds them
until the whole `T` is built. Decrypting now reads the blob in place
into a `T::default()` held in a `Zeroizing<T>`, through serde's
`Deserialize::deserialize_in_place`, and a refusal wipes that value. This
covers the fields of most derived structs, the fields of a struct nested
in one, and the elements of a `Vec` stored before the refusal.
- Decrypting an `OpaqueBlob<T>` now needs `T: Default`. Add
`#[derive(Default)]` to the type.
- stack-encrypt turns on serde_derive's `deserialize_in_place` feature.
Cargo shares a crate's features across a build, so every
`#[derive(Deserialize)]` in a build with stack-encrypt also writes
`deserialize_in_place`. `deserialize` does not change.
- A field serde skips when reading (`#[serde(skip)]` or
`#[serde(skip_deserializing)]`) keeps the value `T::default()` gives
it. A `#[serde(default = "...")]` on that field or on its struct is not
used, so make `T::default()` give the value the field should have.
- serde still builds some values whole, and a refusal inside one of them
still drops what it built unwiped (#1754): an element of a sequence, a
map, an `Option`, a `Box`, an enum, a field read with
`deserialize_with`, and a struct the derive writes no in-place read
for. That is a struct marked `#[serde(transparent)]`, `from` or
`try_from`, one with a `#[serde(flatten)]` field, and one whose every
field uses `deserialize_with`; when `T` is such a struct, a refusal
wipes nothing `T` read. A part that wipes itself on drop, such as a
`Zeroizing<String>`, closes that gap for that part.
- serde reserves room for at most 1 MiB of a sequence's elements before
reading them. A longer sequence regrows its buffer as it is read and
frees each old buffer unwiped, as it did before this change.
- **Encrypting an `OpaqueBlob` wipes the value in every case.** The value is
wiped before `encrypt` returns the pending request, both on success and
when the value cannot be encoded. A failed encoding requests no key. A
Expand Down
15 changes: 15 additions & 0 deletions packages/stack-encrypt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ license-file = "LICENSE"
# Published to crates.io by release-plz.yml; release-plz.toml puts it in the
# `stack-encrypt` version group.

# `serde_derive` is named only to turn on a feature of the derive every
# crate in the build shares (see the dependency), so no code names it and
# `cargo-udeps` reports it as unused. Ignore it.
[package.metadata.cargo-udeps.ignore]
normal = ["serde_derive"]

[dependencies]
# `profile` (native only; stack-kms gates it off wasm32 itself) lets
# `StackCipher::with_detected_credentials()` fall back to the client key
Expand Down Expand Up @@ -68,6 +74,15 @@ futures = { version = "0.3.25", default-features = false, features = ["std"] }
# control data (statistics, options, a plan) into typed messages.
vitaminc-aead-frame = { workspace = true, features = ["serde"] }
serde = { workspace = true }
# `deserialize_in_place`: `#[derive(Deserialize)]` also writes
# `Deserialize::deserialize_in_place` for most structs, which reads each field
# straight into a value the caller already holds. A decrypted
# `OpaqueBlob<T>` is read that way into a `T::default()` it wipes, so a
# field read before a later one is refused is wiped with it, rather than
# dropped as serde's local. Cargo unifies a crate's features across the
# build, so every derive in a build with stack-encrypt writes the method;
# `Deserialize::deserialize` is unchanged.
serde_derive = { workspace = true, features = ["deserialize_in_place"] }
# The order terms' serde: lowercase hex in JSON, raw bytes in a binary
# format, through serdect's constant-time hex.
serdect = { workspace = true }
Expand Down
Loading
Loading