Repository navigation
fix(stack-encrypt,eql-bindings): cut a query's short words only when it cuts no n-gram - #1753
Conversation
|
| Name | Type |
|---|---|
| @cipherstash/eql | Minor |
| stash | Patch |
| @cipherstash/stack-prisma | Patch |
| @cipherstash/basic-example | Patch |
| @cipherstash/e2e | Patch |
| @cipherstash/prisma-example | Patch |
| @cipherstash/stack-drizzle | Patch |
| @cipherstash/stack-supabase | Patch |
| @cipherstash/stack | Patch |
| @cipherstash/wizard | Patch |
| @cipherstash/bench | Patch |
| @cipherstash/test-kit | Patch |
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
|
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.
🟡 Changes recommended
The empty-set failure paths drop owned plaintext without wiping it, violating the owned-mode wiping guarantee and requiring a wiping failure helper with regression coverage.
1 open issue
What changed in this PR
Restores partial-name matching with short-word indexing enabled across Stack Encrypt and EQL v4. Queries retain short-word tokens only when they produce no n-gram; stored filters remain unchanged, so no re-encryption is needed.
Changes:
- Separates stored-value and query token derivation across typed and dynamic paths.
- Adds
QueryBloomFilterand forwards query-specific derivation through EQL query twins. - Adds Rust and Go regression coverage and updates documentation and release notes.
| File | Description |
|---|---|
packages/stack-encrypt/tests/match_short_words.rs |
Tests partial-name matching and token containment. |
packages/stack-encrypt/tests/index.rs |
Tests query derivation for individual and grouped indexes. |
packages/stack-encrypt/src/target/operations.rs |
Adds the query-specific matching operation. |
packages/stack-encrypt/src/target/mod.rs |
Exports matching_query. |
packages/stack-encrypt/src/target/index.rs |
Adds query operations to index traits and implementations. |
packages/stack-encrypt/src/sem/tokenize.rs |
Centralizes query-side short-word filtering. |
packages/stack-encrypt/src/sem/mod.rs |
Aligns filter derivation and verification with query tokens. |
packages/stack-encrypt/src/op/mod.rs |
Routes field queries through query operations. |
packages/stack-encrypt/src/dynamic/term.rs |
Distinguishes stored terms from query probes. |
packages/stack-encrypt/src/dynamic/query.rs |
Uses query-side term derivation. |
packages/stack-encrypt/CHANGELOG.md |
Records matching behavior and new operations. |
packages/eql/tests/encryption/tests/v4_types.rs |
Tests query twins and PostgreSQL partial-name matching. |
packages/eql/tests/encryption/tests/typed_queries.rs |
Checks typed/data-path parity and verification. |
packages/eql/crates/eql-codegen/src/targets.rs |
Generates query twins using QueryBloomFilter. |
packages/eql/crates/eql-codegen/src/bindings.rs |
Selects query-specific Bloom filter field types. |
packages/eql/crates/eql-bindings/src/v4/text.rs |
Updates generated query filter fields. |
packages/eql/crates/eql-bindings/src/v4/mod.rs |
Defines QueryBloomFilter with the existing wire schema. |
packages/eql/crates/eql-bindings/src/v4/answers.rs |
Updates generated query assembly types. |
packages/eql/crates/eql-bindings/src/encryption/query.rs |
Forwards query derivation through TwinIndex. |
packages/eql/crates/eql-bindings/src/encryption.rs |
Implements query-filter encryption and validation. |
packages/eql/crates/eql-bindings/README.md |
Explains revised matching and leakage. |
packages/eql/crates/eql-bindings/CHANGELOG.md |
Records EQL query-filter changes. |
languages/golang/encrypt/README.md |
Updates Go matching guidance. |
languages/golang/encrypt/eql_v4_test.go |
Adds partial-name verification coverage. |
languages/golang/cmd/stashgen/README.md |
Updates generated-field matching guidance. |
languages/golang/CHANGELOG.md |
Records restored partial-name matching. |
.changeset/eql-v4-match-short-words.md |
Updates pending EQL release notes. |
Review effort: Balanced
Mutation testing (cargo-mutants,
|
| caught | missed | unviable | timeout |
|---|---|---|---|
| 11 | 0 | 29 | 0 |
Every mutant in the changed lines was caught by a test.
cipherstash-agent
left a comment
There was a problem hiding this comment.
Review attestation
Reviewed e73459fb · posted from Claude Code · claude-opus-5-5 · effort medium
Sources: code-review · claude-opus-5-5; rust-security agent · claude-opus-5-5; mattpocock code-review agent · claude-opus-5-5
Skills: code-review, rust-security, mattpocock-skills:code-review, review-cross-check, review-post
Findings (7): 7 minor, 4 inline, 3 below.
packages/eql/crates/eql-bindings/src/encryption.rs:407-417(outside diff) minor TheMatchVisitor/bloom_filterdoc still says stored values and queries "take it from the same type, so they always agree" and thatBloomFilter"is the filter of every match query"; every v4 querybfis nowQueryBloomFilter. Same stale claim atv4/mod.rs:112-113(SearchBloomFilter) andeql-codegen/src/bindings.rs:450-456(stored_term_newtype). NameQueryBloomFilteras the query filter and say the two agree only on the tokens a query keeps.packages/stack-encrypt/src/sem/mod.rs:2058-2096(outside diff) minor TheKeysetCipherimpl doc ("These are the query-probe path", "The bytes are identical either way") still presentsmatch_termsas a query probe, contradicting its own new doc at 2145-2155: withshort_wordson,match_terms::<ShortWords>("Mike Ng")keepsngand misses "Mike Nguyen". Say it derives the stored filter; ADR-0004 decision 5 and theMatchConfigdoc (819-824) need the same caveat.packages/stack-encrypt/docs/adr/0009-operators-select-the-index-and-a-query-term-is-not-the-stored-term.md(outside diff) minor ADR-0009 governs query vs stored terms but gets no amendment forIndex::query_operation,Indexes::query_operations, the wrapper-must-forward rule,matching_query, or the short-words query rule. Add an "Amended" section like the existing ones.
Generated by Claude Code
5b83b21 to
ff7cbaf
Compare
e73459f to
a759749
Compare
|
Review round 1, addressed in a759749. The branch was also rebased onto #1752's new head and force-pushed. The rebase hit conflicts in eql-codegen
Checks at a759749, on the whole stack:
|
e8ff073 to
b81001f
Compare
eaf369a to
a914822
Compare
…it cuts no n-gram With MatchOptions::short_words on, a query that held a short word also asked for that word's token beside its n-grams, so the word had to be a whole word of the row. "Mike Ng" no longer found "Mike Nguyen", and "san fr" no longer found "San Francisco", which breaks typeahead and partial names on EQL v4 text columns. A query now keeps its short words only when it cuts no n-gram, which is when the whole query is one short word. "Ng" is still its word token and finds "Ng" and "Mike Ng" but not "Nguyen"; "Mike Ng" is its trigrams alone. The stored side is unchanged, so no stored filter moves. The rule lives once, in tokenize (Tokens::into_query, selected by Side::Query), and every query derivation cuts through it: - QueryTokens::under, so the typed verifier, dynamic::verify and the query preparation all keep the same tokens; - match_term takes a Side; a new target::matching_query operation derives a query's filter, and Index::query_operation (defaulting to operation) is what a field query now derives through. Match overrides it, IndexSpec overrides it, and a set of indexes derives its query terms through the new Indexes::query_operations, each index's query_operation (one index, a tuple and a Vec); - eql-bindings' TwinIndex forwards query_operation to the indexes whose terms its twin carries, so matches on TextMatch, TextSearch and TextSearchOre sends the query's filter, and every other operator the term its index stores; - the dynamic derive takes a Side: query_term and the term probe cut a query, the record path a stored value; - eql-bindings' v4 query twins carry a new QueryBloomFilter (BloomFilter's JSON and schema), whose EncryptTarget derives through matching_query, so TextMatchQuery and TextSearch(Ore)MatchQuery built directly or by the by-name query dispatch follow the rule. eql-codegen emits it for every v4 query twin's bf, and for the bf term of the twins' QueryTwin impls. typed_queries.rs holds a field reference's matches on TextMatch, TextSearch and TextSearchOre to the data path's bytes and verdicts, and checks that "Mike Ng" and "ke Ng" find a stored "Mike Nguyen". Docs, the pending EQL changeset and the CHANGELOGs state the new rule and the leakage: one unique token per short word in every stored value that holds one. Closes #1398
An empty Vec of indexes refused with EmptyIndexes through Encryption::failed, which ignores its source, so in Owned mode the refusal freed the plaintext unwiped. Both Vec::operations and Vec::query_operations now share one fold (each_index, keyed by Side), and its empty branch refuses through a new crate-private Encryption::failed_wiping, which hands the source to WipeSource::wipe first. Two owned wipe-counter tests in tests/index.rs pin it. Index::query_operation and Indexes::query_operations lose their defaults. With a default of the stored term, a wrapper over a short-words Match that forwarded only operation compiled and sent the stored cut, missing "Mike Nguyen" for "Mike Ng". Every built-in index now states its query term, and the CHANGELOG records the breaking change for indexes defined elsewhere. target::matching_query run on its own refuses text that keeps no token with TermError::EmptyTermText (in sem::match_term, for Side::Query), as a field query's prepare does, rather than deriving an empty filter that matches every row. Docs: the Index and Indexes docs point a query at query_operation; the KeysetCipher, MatchConfig, MatchVisitor, SearchBloomFilter and stored_term_newtype docs say match_terms and BloomFilter are the stored cut and QueryBloomFilter the query's; ADR-0004 decision 5 gets a caveat and ADR-0009 an amendment for the query cut.
…the n-gram The docs said a query cuts no n-gram only when it is one short word. That holds for trigrams, but the n-gram length is an option: under 6-grams "Ng Wu" cuts no n-gram and asks for both its words. Say what the condition is instead. The EQL and Go docs keep "one two-letter word", because both use 3-grams.
b81001f to
931be62
Compare
…n plain language The docs this branch added or changed were hard to follow. They used "cut" for several ideas, packed several facts into each sentence, and mixed the value an app stores with the query it sends. Each passage now leads with what the reader must do or must not do, then gives the reason, with "Mike Ng" and "Mike Nguyen" as the example. "n-gram", "short word" and "token" are defined where they first appear. The rule is stated one way everywhere: a query keeps its short words only when its whole text is shorter than one n-gram. In the EQL and Go docs that is a query of one two-letter word. The rewrite covers the rustdoc and comments in stack-encrypt, eql-bindings and eql-codegen, the ADR-0004 and ADR-0009 amendments, the stack-encrypt, eql-bindings and Go changelogs, the changeset, and the eql-bindings and Go READMEs. Every fact is kept, including the leakage note, the upgrade steps for the new required methods, and why query_operation has no default. Rustdoc and Go docs no longer describe what was visible before the option; they say what is visible without it. No code changes.
coderdan
left a comment
There was a problem hiding this comment.
Human pass. LGTM.


Summary
The match index's short-words option makes two-letter words such as "Ng" searchable. With it on, a search for "Mike Ng" stopped finding "Mike Nguyen", and "san fr" stopped finding "San Francisco", because the query also demanded the short word as a whole word. Now a query uses its short words only when it cuts no 3-letter piece, which means the whole query is short words. "Ng" still finds "Ng" and "Mike Ng" and not "Nguyen". "Mike Ng", "ke Ng" and "san fr" find the longer names again. Stored values don't change, so nothing needs re-encrypting.
Changes
tokenize: the rule lives in one place,Tokens::into_query, chosen by a crate-privateSide::{Stored, Query}.sem:QueryTokenscuts a query as a query, andverifycuts the row as stored.match_termtakes aSide.match_query.target:target::matching_query(a query's filter) andIndex::query_operation.query_operationdefaults tooperation, andMatchoverrides it. A field query now derives throughquery_operation.Indexes::query_operationsfor a set of indexes. AVecrefuses an empty set before any key request, and wipes an owned plaintext when it does.Index::query_operationandIndexes::query_operationsare required, so a wrapper index can't quietly send the stored filter. The CHANGELOG has upgrade steps.matching_queryand the other query cuts refuse text that keeps no token (TermError::EmptyTermText), instead of returning a filter that matches every row.dynamic:query_termand thetermprobe cut as a query, and the record path cuts as stored.v4::terms::QueryBloomFilter, with the same JSON and schema asBloomFilter. ItsEncryptTargetgoes throughmatching_query, and it refuses an empty filter.TwinIndexforwards query derivation to the indexes whose terms its twin carries, throughIndexes::query_operations. Since feat(eql-bindings): answer order queries from a field reference #1752 also lets theTextSearchandTextSearchOretwins answereq, the orderings andmatches, theirmatchessends the query-side filter too.bfis now aQueryBloomFilter.v4/text.rsandv4/answers.rsare regenerated, andeql_gen.gois unchanged.MatchOptions::short_words, thesemleakage section, thematch_termsanddynamic::termdocs, and the eql-bindings README.encrypt/README.mdandcmd/stashgen/README.md..changeset/eql-v4-match-short-words.mdis edited, because its "Mike Ng does not find Mike Nguyen" sentence is now wrong.tests/match_short_words.rs: a table covering "Ng", "Mike Ng", "ke Ng", "san fr", "Li Wu" and "Mike Ngo", plus a typeahead proptest.packages/stack-encrypt/tests/index.rs,given_a_set_holding_a_match_index_with_short_words: one index, a tuple and aVecderive the query filter fromquery_operationsand the stored filter fromoperations.typed_queries.rs,given_a_two_letter_word_in_a_match_query, overTextMatch,TextSearchandTextSearchOre: the field query and the data path keep the same rows and produce the same bytes. A stored "Mike Nguyen" filter contains the "Mike Ng" and "ke Ng" query filters. This test fails ifTwinIndexsends the stored filter.Verify("Mike Ng")keeps "Mike Ng" and "Mike Nguyen".Verification
cargo test -p stack-encrypt --all-features: all test binaries pass, including ui and doctests.fmt,clippy -D warningsanddoc -D warningsare clean for stack-encrypt.packages/eql:cargo testpasses for eql-encryption-tests, eql-bindings, eql-domains and eql-codegen.go test ./...passes,go generate ./...produces no drift, and golangci-lint reports 0 issues.--in-diff: 29 mutants, 9 caught, 20 unviable, 0 missed.tasks/build.sh, on a throwaway PostgreSQL 17, passes every suite intest:encryption:postgres(63 tests), includingpostgres_finds_two_letter_surnames.cargo test -p stack-encrypt --all-features: 1652 passed, 0 failed.cargo doc -D warningsfor eql-bindings fails with 10 broken links inv4/json_tree.rs. The same errors are onnext, and none comes from this PR.Related
Closes #1398. Stacked on #1752.
Review notes
Tokens::into_query.Index::query_operationandIndexes::query_operationsare required. An index that wraps others has to forward them, or it would quietly send the stored filter. Making them required turns that mistake into a compile error.TwinIndexforwards to the indexes whose terms its twin carries.QueryBloomFilter: the EQL data path builds query twins through thebffield type'sEncryptTarget, so a query type is the clean place for the rule. It follows the existingSearchBloomFilterpattern. It changes public field types in the unreleased v4 module only, and its wire JSON and schema don't change.