Repository navigation
feat(stack-encrypt,eql-bindings,golang): open one child of a JSON node, bound to its parent - #1751
Conversation
🦋 Changeset detectedLatest commit: ab20b29 The changes in this PR will be included in the next version bump. This PR includes changesets to release 12 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
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
|
There was a problem hiding this comment.
🔵 Needs a closer look
Human cryptographic review is needed to validate the new child-opening API and shared subtree verifier’s assurance boundary, since unauthenticated tags permit documented sibling-element substitutions.
No open issues 🎉
4 files not reviewed
languages/golang/encrypt/example/json/customer_stash.go: Generated filelanguages/golang/encrypt/internal/testusers/customer_stash.go: Generated filelanguages/golang/encrypt/internal/testusers/entity_stash.go: Generated filelanguages/golang/encrypt/internal/testusers/subscriber_stash.go: Generated file
What changed in this PR
Adds single-child JSON reads across Stack Encrypt, eql-bindings, and the Go SDK, addressing #1677 without fetching the parent’s whole subtree. Reads reuse existing parent-link checks; stored bytes, SQL, and the guest ABI remain unchanged.
Changes:
- Adds Rust
JsonChildandJsonTreeChildtypes, plus dynamicchildrenopening support. - Changes Go’s generated
Childrenmethod to returnJSONChildren, with token binding, opening, and redacted logging; callers needingJSONTokenuse.Token(). - Adds child-read tests and conformance enrollment, and updates documentation and release notes.
| File | Description |
|---|---|
scripts/__tests__/stack-eql-conformance.test.mjs |
Requires the new child-read conformance entry. |
packages/stack-encrypt/tests/json_read_checks.rs |
Tests child values, parent checks, and refusals. |
packages/stack-encrypt/tests/json_operators.rs |
Tests dynamic child reads and input validation. |
packages/stack-encrypt/src/refusal.rs |
Documents child-group input refusals. |
packages/stack-encrypt/src/op/mod.rs |
Documents opening children returned by the operator. |
packages/stack-encrypt/src/json/query.rs |
Adds JsonSubtreeKey::open_child and its guarantees. |
packages/stack-encrypt/src/json/mod.rs |
Defines the prepared JsonChild type. |
packages/stack-encrypt/src/json/derive.rs |
Implements child decryption using shared walk checks. |
packages/stack-encrypt/src/field_reference/json.rs |
Documents opening children through field-reference keys. |
packages/stack-encrypt/src/dynamic/query.rs |
Documents the dynamic child-read contract. |
packages/stack-encrypt/src/dynamic/json_query.rs |
Parses and opens dynamic children requests. |
packages/stack-encrypt/src/cipher.rs |
Extends non-leaf error guidance to child reads. |
packages/stack-encrypt/CHANGELOG.md |
Records the engine API and refusal behavior. |
packages/eql/tests/encryption/tests/json_tree.rs |
Adds typed and PostgreSQL child-read coverage. |
packages/eql/docs/reference/json-tree.md |
Replaces the old limitation with child-opening guidance. |
packages/eql/crates/eql-bindings/src/v4/json_tree.rs |
Adds JsonTreeChild and delegates opening to the engine. |
packages/eql/crates/eql-bindings/CHANGELOG.md |
Records the typed child-opening API. |
languages/golang/stashgen/testdata/stubsdk/encrypt/gensupport/gensupport.go |
Adds the generator-support stub. |
languages/golang/stashgen/testdata/stubsdk/encrypt/encrypt.go |
Adds the JSONChildren SDK stub. |
languages/golang/stashgen/emit.go |
Generates prepared Children methods. |
languages/golang/encrypt/records.go |
Allows preparing child reads through bound ciphers. |
languages/golang/encrypt/README.md |
Adds child-read examples and usage guidance. |
languages/golang/encrypt/query.go |
Documents binding support for child-read operands. |
languages/golang/encrypt/json.go |
Implements JSONChildren, opening, binding, and redaction. |
languages/golang/encrypt/json_tree_test.go |
Tests guest child reads and scoped operands. |
languages/golang/encrypt/json_postgres_test.go |
Tests generated child reads against PostgreSQL. |
languages/golang/encrypt/json_fields_test.go |
Tests binding, zero values, redaction, and opening. |
languages/golang/encrypt/internal/testusers/subscriber_stash.go |
Regenerates subscriber child-read methods. |
languages/golang/encrypt/internal/testusers/entity_stash.go |
Regenerates the entity child-read method. |
languages/golang/encrypt/internal/testusers/customer_stash.go |
Regenerates customer child-read methods. |
languages/golang/encrypt/guest/src/ops.rs |
Documents children on the existing guest export. |
languages/golang/encrypt/gensupport/json.go |
Prepares typed child reads for generated code. |
languages/golang/encrypt/example/json/customer_stash.go |
Regenerates the example child-read method. |
languages/golang/encrypt/doc.go |
Documents child reads through bound ciphers. |
languages/golang/cmd/stashgen/README.md |
Updates generated API return types. |
languages/golang/CHANGELOG.md |
Records functionality and the Go migration path. |
docs/plans/2026-10-24-stack-encrypt-api-plan.md |
Records implementation of single-child opening. |
conformance/stack-encrypt/v1/eql-json-v1.enrollment.json |
Enrolls cross-language child-read evidence. |
conformance/stack-encrypt/README.md |
Includes child reads in the profile summary. |
conformance/stack-encrypt/eql-json-contract.md |
Defines the json-child-v1 requirement. |
conformance/stack-encrypt/coverage.md |
Adds child reads to documented coverage. |
.changeset/eql-json-tree-open-one-child.md |
Adds an EQL minor-release changeset. |
Review effort: Balanced
cipherstash-agent
left a comment
There was a problem hiding this comment.
Review attestation
Reviewed c146ba53 · posted from Claude Code (scheduled routine) · claude-opus-5-5 · effort medium
Sources: code-review · claude-opus-5-5; mattpocock-skills:code-review (Standards and Spec axes) · claude-opus-5-5; rust-security agent · claude-opus-5-5 (no findings)
Skills: code-review, mattpocock-skills:code-review, company-skills:rust-security, company-skills:review-cross-check, company-skills:review-post
Every finding below was re-verified against c146ba53 and cross-checked against existing feedback (none carried findings).
Findings (10): 1 major, 9 minor — 8 inline, 2 below.
docs/plans/2026-10-24-stack-encrypt-api-plan.md:973(outside diff) minor Target state still says "A Go program cannot open one child of a JSON node, bound to its parent" under "Two parts … not in Go yet", which this PR's Remaining-work entry (1287-1295) marks done. Drop the bullet and make the intro singular.docs/plans/2026-10-24-stack-encrypt-api-plan.md:966(outside diff) minor "An upgrade alone does not change a committed*_stash.gofile, apart from the one regeneration the handle rename needs" (repeated near 1763) is now false: the generatedChildrenchanges for every JsonSearch field. Name this as a second regeneration or reword as a target rule.
Source: code-review · claude-opus-5-5
Generated by Claude Code
Mutation testing (cargo-mutants,
|
| caught | missed | unviable | timeout |
|---|---|---|---|
| 26 | 0 | 48 | 0 |
Every mutant in the changed lines was caught by a test.
aafa693 to
375e611
Compare
…e, bound to its parent
Reading one child of a JSON node needed the parent's whole subtree: the
SQL returns a node's children (eql_v4.json_tree_children), but nothing
opened one of them and checked it belonged to the node the caller asked
about. So a program fetched and opened the parent's subtree, which
transfers more data and shows the server a different set of tokens.
The engine now opens one entry json_tree_children returned against the key
of its parent's path. JsonSubtreeKey::open_child(node) gives a JsonChild,
which opens to the child's value (a scalar, or {} or [] for an empty
container). The open reuses the subtree rebuild's own checks rather than a
second copy: ChainWalk::node is split into place_row, open_row and value,
and the parent-link check it made in child() is check_parent_link, which
both the rebuild and the lone child call. A lone child is placed one level
down, opened under the digest of no children (a container with children
does not open alone: JsonNotALeaf), its selector checked as its parent's
path extended by its decrypted label, and its self tag checked as the token
that label derives under the parent's token. An entry with no parent tag,
and a key of a path with a wildcard, are refused before any key request.
The dynamic interface's json_open takes the operation "children" (one
entry or none per group), so the Go guest's existing se_json_open export
carries it and no export is added. eql-bindings has JsonTreeChild, the
EQL-typed twin of JsonTreeExtracted and JsonTreeSubtree.
In Go, the generated Children now returns encrypt.JSONChildren: Token()
to bind and Open(ctx, entries) to open each child. It binds as its token,
so code that passed the old JSONToken to a query keeps working. Children
prepares a read, so like Selector and Subtree it is no longer refused
through a cipher with a binding; ChildCount still is.
The eql-json-v1 conformance profile enrolls json-child-v1, with Rust
engine, EQL, Go and PostgreSQL evidence. No stored bytes change.
Closes #1677
… child
A child opened on its own now says which child of its parent it is.
json_tree_children returns an object's members in a random order, and
the opened child carried only its value, so a caller could not tell one
member from another. The engine already decrypts and checks the child's
label (its key, or its index); it now returns it.
- stack-encrypt: JsonChild opens to a JsonChildPlaintext, with key(),
index() and value(). The key and the index are held in Protected and
the value in a JsonPlaintext, so all three are wiped on drop, and Debug
is redacted. dynamic::json_open writes each child as a map,
{"key", "json"} or {"index", "json"}.
- eql-bindings: JsonTreeChild opens to the same JsonChildPlaintext.
children(path).encrypt_keyed(&keyset) returns the token to bind with
the JsonSubtreeKey that opens what it returns, from one derivation, so
an EQL caller no longer derives the key a second time.
- Go: JSONChildren.Open returns []JSONChildValue, with Key() and Index()
(comma-ok) and the JSON text, printed and logged redacted.
Cipher.JSONOpen refuses the children operation, whose values it cannot
carry. The three prepared reads print and log through one embedded
redactedRead instead of three copies of four methods.
- Go: the read operators (selector, subtree, children) are constants in
internal/record with IsJSONRead, used by operandPlan, gensupport and
each read's Open. A test asks the engine which operators json_open
opens and checks that set against IsJSONRead.
- Go: gensupport.JSONNodeToken derives as child_count, so a *_stash.go
generated before JSONChildren, whose Children calls it with children,
is still refused through a cipher with a binding. The token is the
same. Other operators are refused.
- Docs: the Go README, CHANGELOG bullets and the generated Children
comment are split into short sentences; the EQL leakage reference
describes a child read; the API plan no longer lists the child read as
missing from Go, and names the Children change a regeneration picks up.
- Conformance: json-child-v1 enrolls the depth refusal and the new Go
tests.
No stored bytes change.
c146ba5 to
3c584e6
Compare
|
Review round 1, addressed in 3c584e6. The branch was also rebased onto #1750's new head and force-pushed.
Checks, run on the stack at #1752's head, which includes this PR:
The fix agent's own run, before the restack:
|
There was a problem hiding this comment.
🔵 Needs a closer look
Partial decryption and the shared verifier refactor need human cryptographic review of unauthenticated-tag substitution limits, while cross-language and PostgreSQL validation remains independently unverified.
No open issues 🎉
4 files not reviewed
languages/golang/encrypt/example/json/customer_stash.go: Generated filelanguages/golang/encrypt/internal/testusers/customer_stash.go: Generated filelanguages/golang/encrypt/internal/testusers/entity_stash.go: Generated filelanguages/golang/encrypt/internal/testusers/subscriber_stash.go: Generated file
Review effort: Balanced
coderdan
left a comment
There was a problem hiding this comment.
Some open questions and API improvements warranted.
The plain-language checker reads a project's own names from .plain-language.json and treats each as one word, so product names do not read as jargon or unexplained abbreviations.
…alue, and explain the read in plain words A child of a JSON node could only decrypt into a JsonChildPlaintext, so a caller who wanted the value had a different type from a whole-document or subtree read. A JsonChild, and eql-bindings' JsonTreeChild, now also decrypt into a JsonPlaintext. Both targets share one code path: the label is still decrypted and checked, then wiped, and only the value is returned. JsonChildPlaintext stays for a caller that needs the member's key or the element's index, since the database returns an object's members in a random order. JsonChildPlaintext's Debug is now derived with vitaminc's OpaqueDebug in place of a hand-written impl. JsonPlaintext keeps its own Debug: the derive prints a different string for it, so it is not a drop-in. The docs this change set added are rewritten in plain words. Each one that introduces the child read walks the same three steps: your app derives the parent's token and key, the database (EQL) returns the parent's children as encrypted entries, and your app checks and decrypts each one, fetching the data key from ZeroKMS. The doc examples that read entries from a stored JsonDocument say they stand in for the database, and show the SQL that returns those entries in production. Tests through the public API cover the new target: each value opens, and every wrong entry is refused with the same error for both targets.
Summary
A program can now read one child of an encrypted JSON node without fetching the parent's whole subtree. It sends the parent's token to
eql_v4.json_tree_children(the EQL SQL function that lists a node's children) and opens each returned entry on its own. Each one opens to its authenticated member key or array index together with its value. The client checks that each entry really is a child of the node it asked about. This works in Rust (stack-encrypt and eql-bindings), in the Go SDK, and in theeql-json-v1conformance profile. No stored bytes change.Changes
JsonSubtreeKey::open_child(node), which returns aJsonChild. AJsonChildopens to aJsonChildPlaintext: the child's key or index (key(),index(), held inProtected) and its value (value()), which is a scalar, or{}/[]for an empty container.Debugis redacted.JsonFieldQuery<T, Children, Ready>::encrypt_keyed, which returns the children token together with the key that opens each child.ChainWalk::nodeis split intoplace_row,open_rowandvalue, and the parent-token check from the privatechild()becomescheck_parent_link. The whole-subtree walk and the new single-child read call the same functions.JsonPathWildcard).JsonNotALeaf.dynamic::json_openandcheck_json_opentake{"operation":"children","path":…}, and write each child as{"key"|"index", "json"}. The Go guest's existingse_json_openexport carries this, so there's no new export and no ABI change.JsonTreeChild::from_key(&JsonSubtreeKey, JsonTreeEntry), the EQL equivalent ofJsonTreeExtractedandJsonTreeSubtree.Children(ctx, c, path)returnsencrypt.JSONChildren[E]. It hasToken(),Open(ctx, entries) ([]json.RawMessage, error), and aValue()that binds as the token, and it is redacted when printed or logged.Childrenis now allowed through a cipher with a binding, likeSelectorandSubtree.*_stash.gofiles are regenerated.json-child-v1, ineql-json-v1.enrollment.json. Its evidence comes from the engine, eql-typed, postgres, go and go-postgres suites. The contract table, README andcoverage.mdare updated to match.json-tree.mddescribes opening a child; the old line saying it "cannot be done" is gone.doc.go, the stashgen README, rustdoc, and the plan item are updated.@cipherstash/eql.Verification
cargo test -p stack-encrypt --all-featurespasses, including the trybuilduibinary with no snapshot change.-D warnings, andcargo fmt --check, are clean.--in-diff: 52 mutants, 17 caught, 0 missed, 35 unviable.cargo test -p eql-encryption-tests -p eql-bindings --all-featurespasses.json_treePostgreSQL tests, including the newpostgres_each_child_opens_against_its_parent.go test ./...passes, as do the nestedencrypt/exampleandencrypt/encrypttestmodules.go generate ./...produces no drift.STACK_CONFORMANCE_REQUIRED=1.mise run test:conformance:eql[:postgres]wrapper scripts. The suites they name were run directly instead.cargo doc -D warningsfor eql-bindings fails only on errors that already exist onnext.Related
Closes #1677. Stacked on #1750. Builds on the typed JSON field reference methods from #1687.
Review notes
json_tree_children,Op::Children, GoChildren, and the Rust field reference'schildren(path).JsonSubtreeKey::open_childreturningJsonChild, matchingJsonSelector::openreturningJsonExtracted.Children→JSONChildren.Open, matchingSelector→JSONSelection.Open.open_child.{}/[], unlike->'sJsonExtracted, becausejsonb_array_elementsreturns them.Childrennow returnsJSONChildreninstead ofJSONToken.JSONChildrenbinds as its token, so existingdb.Query(…, token)calls keep working. Only code that keeps the result typed asJSONTokenbreaks; it calls.Token().