From 82d873e08a40eecab63b3318910e77a85037bb13 Mon Sep 17 00:00:00 2001 From: Lindsay Holmwood Date: Sat, 28 Nov 2026 00:36:34 +1100 Subject: [PATCH 1/2] fix(eql-bindings): leave the label out of column refusals A field's label is an encryption context, and the SDKs promise that an error never shows the value of a context. TargetError::Context and QueryLabelError::NotAColumn put the label in their message, and their derived Debug printed it too, so unwrap and {:?} logged it. Both messages now say "the field's label" or "the query's label" in place of the label. Both types write Debug by hand and print the label as ; TargetError prints every other variant as the derived Debug did. The label field stays, so code that builds or matches the variants still compiles. This follows the stack-encrypt fix in #1983. Refs #1999 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01CtEQzxj55RUn35dkbhdwQk --- .../eql-bindings-context-label-redacted.md | 10 ++ packages/eql/crates/eql-bindings/CHANGELOG.md | 8 ++ .../eql-bindings/src/encryption/query.rs | 63 ++++++++- .../eql-bindings/src/encryption/targets.rs | 123 +++++++++++++++++- 4 files changed, 196 insertions(+), 8 deletions(-) create mode 100644 .changeset/eql-bindings-context-label-redacted.md diff --git a/.changeset/eql-bindings-context-label-redacted.md b/.changeset/eql-bindings-context-label-redacted.md new file mode 100644 index 000000000..7dfd395eb --- /dev/null +++ b/.changeset/eql-bindings-context-label-redacted.md @@ -0,0 +1,10 @@ +--- +'@cipherstash/eql': patch +--- + +**eql-bindings no longer shows a field's label in a column refusal** (`stack-encrypt` feature, #1999). A label is an encryption context, and an error never shows the value of a context. + +- `encryption::targets::TargetError::Context` was `"app/users/email" is not an EQL column identifier: expected two segments, table and column`. It is now `the field's label is not an EQL column identifier: expected two segments, table and column`. +- `encryption::query::QueryLabelError::NotAColumn` now starts `the query's label is not an EQL column identifier`. A typed query returns it inside `stack_encrypt::Error::Other`. +- `Debug` shows the label of both errors as ``. Both types now write `Debug` by hand. `TargetError` prints every other variant as the derived `Debug` did. +- Both variants keep their `label` field, so code that builds or matches them still compiles. Code that needs the label takes it from the plan or the query. diff --git a/packages/eql/crates/eql-bindings/CHANGELOG.md b/packages/eql/crates/eql-bindings/CHANGELOG.md index 29085ffb4..5a2681306 100644 --- a/packages/eql/crates/eql-bindings/CHANGELOG.md +++ b/packages/eql/crates/eql-bindings/CHANGELOG.md @@ -9,6 +9,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- **A column refusal no longer shows the field's label** (#1999). A label + is an encryption context, and an error never shows the value of a + context. The message of `encryption::targets::TargetError::Context` + now starts `the field's label`, and the message of + `encryption::query::QueryLabelError::NotAColumn` now starts + `the query's label`. `Debug` shows the label of both as + ``. Both variants keep their `label` field, so code that + builds or matches them still compiles. - **The by-name target entry points borrow the plaintext as a `Frame`, and open into an `OwnedFrame`** (#1955). `encryption::targets::encrypt`, `encrypt_with` and `query`, and the `v4::targets` table, take the diff --git a/packages/eql/crates/eql-bindings/src/encryption/query.rs b/packages/eql/crates/eql-bindings/src/encryption/query.rs index fdaf9e153..0330829c8 100644 --- a/packages/eql/crates/eql-bindings/src/encryption/query.rs +++ b/packages/eql/crates/eql-bindings/src/encryption/query.rs @@ -396,14 +396,19 @@ fn check_column(label: &Label) -> Result<(), Error> { /// The label of a derived record's field reference is the record's scope and /// the field's name, two segments, so a query from such a field reference is never /// refused this way. -#[derive(Clone, Debug, PartialEq, Eq)] +/// +/// The message and `Debug` leave out the label: a label is an encryption +/// context, and an error never shows a context's value. +#[derive(Clone, PartialEq, Eq)] #[non_exhaustive] pub enum QueryLabelError { /// The label names no column: an EQL query value stores the /// [`Identifier`] it queries, a two-segment label, table then column. /// The data path refuses the same label as `TargetError::Context`. NotAColumn { - /// The label, rendered. + /// The label, rendered. Never shown: not in the message or `Debug`. + /// Kept so that code which builds or matches this variant still + /// compiles. label: String, }, } @@ -411,14 +416,26 @@ pub enum QueryLabelError { impl fmt::Display for QueryLabelError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - Self::NotAColumn { label } => write!( - f, - "{label:?} is not an EQL column identifier: expected two segments, table and column" + Self::NotAColumn { .. } => f.write_str( + "the query's label is not an EQL column identifier: expected two segments, table \ + and column", ), } } } +/// The derived form, except that the label is shown as ``. +impl fmt::Debug for QueryLabelError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Self::NotAColumn { .. } => f + .debug_struct("NotAColumn") + .field("label", &format_args!("")) + .finish(), + } + } +} + impl std::error::Error for QueryLabelError {} /// The column a query's label names. A field query calls `query` only @@ -648,3 +665,39 @@ impl Serialize for MatchTwin { self.twin.serialize(serializer) } } + +#[cfg(test)] +mod tests { + use super::*; + + /// A label is an encryption context, and an error never shows a + /// context's value: not in the message, not in `Debug`. + #[test] + fn a_label_refusal_never_shows_the_label() { + let label = Label::new(&["tenant-acme", "users", "email"]).unwrap(); + let Err(Error::Other(error)) = check_column(&label) else { + panic!("a three-segment label is not a column"); + }; + let refusal = error + .downcast_ref::() + .expect("the refusal is a QueryLabelError"); + assert!(matches!( + refusal, + QueryLabelError::NotAColumn { label } if label == "tenant-acme/users/email" + )); + let shown = [ + error.to_string(), + format!("{error:?}"), + format!("{refusal:#?}"), + ]; + for text in &shown { + assert!(!text.contains("tenant-acme"), "the label leaked: {text}"); + } + assert_eq!( + error.to_string(), + "the query's label is not an EQL column identifier: expected two segments, table and \ + column" + ); + assert_eq!(format!("{refusal:?}"), "NotAColumn { label: }"); + } +} diff --git a/packages/eql/crates/eql-bindings/src/encryption/targets.rs b/packages/eql/crates/eql-bindings/src/encryption/targets.rs index 790dd886f..f973c5f27 100644 --- a/packages/eql/crates/eql-bindings/src/encryption/targets.rs +++ b/packages/eql/crates/eql-bindings/src/encryption/targets.rs @@ -236,7 +236,10 @@ pub fn target(name: &str) -> Option<&'static Target> { /// are statements about the name, the context or the value. The encryption /// itself failing arrives through the returned [`Pending`] as a /// [`stack_encrypt::Error`]. -#[derive(Debug, thiserror::Error)] +/// +/// `Debug` is written by hand so that it leaves out +/// [`Context`](Self::Context)'s label, which is an encryption context. +#[derive(thiserror::Error)] #[non_exhaustive] pub enum TargetError { /// No EQL type has this name. @@ -281,9 +284,16 @@ pub enum TargetError { }, /// The field's context is not an EQL column: an [`Identifier`] is a /// two-segment label, table then column, and this label is not one. - #[error("{label:?} is not an EQL column identifier: expected two segments, table and column")] + /// + /// The message and `Debug` leave out the label: a label is an + /// encryption context, and an error never shows a context's value. + #[error( + "the field's label is not an EQL column identifier: expected two segments, table and column" + )] Context { - /// The label, rendered. + /// The label, rendered. Never shown: not in the message or `Debug`. + /// Kept so that code which builds or matches this variant still + /// compiles. label: String, }, /// The value is not of the type's plaintext kind. Nothing is converted: @@ -333,6 +343,56 @@ pub enum TargetError { }, } +/// The derived form, except that [`TargetError::Context`]'s label is shown +/// as ``. A `Debug` of an error reaches logs through `unwrap` and +/// `{:?}`, so it keeps the rule the message keeps. +impl fmt::Debug for TargetError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Self::Unknown { name } => f.debug_struct("Unknown").field("name", name).finish(), + Self::Unproducible { name, reason } => f + .debug_struct("Unproducible") + .field("name", name) + .field("reason", reason) + .finish(), + Self::NoQuery { name } => f.debug_struct("NoQuery").field("name", name).finish(), + Self::DocumentQuery { name } => { + f.debug_struct("DocumentQuery").field("name", name).finish() + } + Self::NoIndex { name, index } => f + .debug_struct("NoIndex") + .field("name", name) + .field("index", index) + .finish(), + Self::Context { .. } => f + .debug_struct("Context") + .field("label", &format_args!("")) + .finish(), + Self::Plaintext { + target, + expected, + found, + } => f + .debug_struct("Plaintext") + .field("target", target) + .field("expected", expected) + .field("found", found) + .finish(), + Self::Json { target, source } => f + .debug_struct("Json") + .field("target", target) + .field("source", source) + .finish(), + Self::Options { name } => f.debug_struct("Options").field("name", name).finish(), + Self::Stored { target, source } => f + .debug_struct("Stored") + .field("target", target) + .field("source", source) + .finish(), + } + } +} + /// Which cipher [`decrypt`] opens through: the client, which opens a value /// sealed under any of its keysets, or one keyset, which refuses a value /// sealed under another ([`stack_encrypt::Error::ForeignKeyset`]) before any @@ -1021,6 +1081,63 @@ mod tests { } } + /// A label is an encryption context, and an error never shows a + /// context's value: not in the message, not in `Debug`. + #[test] + fn a_context_refusal_never_shows_the_label() { + let error = Identifier::from_label(&label(&["tenant-acme", "users", "email"])).unwrap_err(); + let shown = [ + error.to_string(), + format!("{error:?}"), + format!("{error:#?}"), + ]; + for text in &shown { + assert!(!text.contains("tenant-acme"), "the label leaked: {text}"); + } + assert_eq!( + error.to_string(), + "the field's label is not an EQL column identifier: expected two segments, table and \ + column" + ); + assert_eq!(format!("{error:?}"), "Context { label: }"); + } + + /// The hand-written `Debug` keeps the derived form for the variants that + /// carry no context. + #[test] + fn debug_keeps_the_derived_form_for_the_other_variants() { + assert_eq!( + format!( + "{:?}", + TargetError::NoIndex { + name: "TextEq", + index: "ore" + } + ), + "NoIndex { name: \"TextEq\", index: \"ore\" }" + ); + assert_eq!( + format!( + "{:?}", + TargetError::Plaintext { + target: "TextEq", + expected: ValueKind::String, + found: None, + } + ), + "Plaintext { target: \"TextEq\", expected: String, found: None }" + ); + assert_eq!( + format!( + "{:?}", + TargetError::Unknown { + name: "Nope".into() + } + ), + "Unknown { name: \"Nope\" }" + ); + } + #[test] fn the_table_is_catalog_ordered_and_names_each_type_once() { let names: Vec<&str> = targets().iter().map(|t| t.name).collect(); From 72b95147f6083fb886f869006629264183c23210 Mon Sep 17 00:00:00 2001 From: Lindsay Holmwood Date: Sat, 28 Nov 2026 02:50:12 +1100 Subject: [PATCH 2/2] fix(eql-bindings): stop quoting stored bytes in TargetError::Stored TargetError::Stored put serde_json's own message in its Display and Debug. That message quotes the string the parser refused, and the input is stored ciphertext. targets::decrypt returns this error to a direct Rust caller. The data path already describes it by kind and position (resolver.rs, describe_json_error). The message and Debug now use describe_json_error too. The source field and source() still return the parser's error, so a caller who needs the detail can still read it. The encryption test that read "version 3" from the message now reads it from source. The changeset and CHANGELOG no longer say that every error leaves out a context: stack-encrypt's TargetError::Column still shows the label on the data path until #1983 lands. Refs #1999 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01CtEQzxj55RUn35dkbhdwQk --- .../eql-bindings-context-label-redacted.md | 6 ++- packages/eql/crates/eql-bindings/CHANGELOG.md | 17 +++++-- .../eql-bindings/src/encryption/targets.rs | 46 +++++++++++++++++-- .../eql/tests/encryption/tests/targets.rs | 22 +++++---- 4 files changed, 71 insertions(+), 20 deletions(-) diff --git a/.changeset/eql-bindings-context-label-redacted.md b/.changeset/eql-bindings-context-label-redacted.md index 7dfd395eb..e47b8fd37 100644 --- a/.changeset/eql-bindings-context-label-redacted.md +++ b/.changeset/eql-bindings-context-label-redacted.md @@ -2,9 +2,11 @@ '@cipherstash/eql': patch --- -**eql-bindings no longer shows a field's label in a column refusal** (`stack-encrypt` feature, #1999). A label is an encryption context, and an error never shows the value of a context. +**Two eql-bindings errors no longer show a field's label, and one no longer quotes stored bytes** (`stack-encrypt` feature, #1999). A label is an encryption context. `TargetError::Context` and `QueryLabelError::NotAColumn` no longer show it. On the data path, `stack-encrypt`'s `TargetError::Column` still shows the label until #1983 lands. - `encryption::targets::TargetError::Context` was `"app/users/email" is not an EQL column identifier: expected two segments, table and column`. It is now `the field's label is not an EQL column identifier: expected two segments, table and column`. - `encryption::query::QueryLabelError::NotAColumn` now starts `the query's label is not an EQL column identifier`. A typed query returns it inside `stack_encrypt::Error::Other`. -- `Debug` shows the label of both errors as ``. Both types now write `Debug` by hand. `TargetError` prints every other variant as the derived `Debug` did. +- `Debug` shows the label of both errors as ``. Both types now write `Debug` by hand. - Both variants keep their `label` field, so code that builds or matches them still compiles. Code that needs the label takes it from the plan or the query. +- `encryption::targets::TargetError::Stored` now shows only the kind, line, and column of the JSON parser's error, in its message and in `Debug`. The parser's own message could quote the stored ciphertext it refused. For example: `stored value is not a TextEq: unexpected data at line 1 column 19`. Its `source` field and `source()` still return the parser's error. +- `TargetError` prints every other variant in `Debug` as the derived `Debug` did. diff --git a/packages/eql/crates/eql-bindings/CHANGELOG.md b/packages/eql/crates/eql-bindings/CHANGELOG.md index 5a2681306..ec00548cc 100644 --- a/packages/eql/crates/eql-bindings/CHANGELOG.md +++ b/packages/eql/crates/eql-bindings/CHANGELOG.md @@ -9,14 +9,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed -- **A column refusal no longer shows the field's label** (#1999). A label - is an encryption context, and an error never shows the value of a - context. The message of `encryption::targets::TargetError::Context` - now starts `the field's label`, and the message of +- **Two column refusals no longer show the field's label** (#1999). A + label is an encryption context. The message of + `encryption::targets::TargetError::Context` now starts + `the field's label`, and the message of `encryption::query::QueryLabelError::NotAColumn` now starts `the query's label`. `Debug` shows the label of both as ``. Both variants keep their `label` field, so code that - builds or matches them still compiles. + builds or matches them still compiles. On the data path, + `stack-encrypt`'s `TargetError::Column` still shows the label until + #1983 lands. +- **`TargetError::Stored` no longer quotes the stored bytes** (#1999). Its + message and `Debug` now show only the kind, line, and column of the + JSON parser's error. The parser's own message could quote the stored + ciphertext it refused. The `source` field and `source()` still return + the parser's error. - **The by-name target entry points borrow the plaintext as a `Frame`, and open into an `OwnedFrame`** (#1955). `encryption::targets::encrypt`, `encrypt_with` and `query`, and the `v4::targets` table, take the diff --git a/packages/eql/crates/eql-bindings/src/encryption/targets.rs b/packages/eql/crates/eql-bindings/src/encryption/targets.rs index f973c5f27..696126dcc 100644 --- a/packages/eql/crates/eql-bindings/src/encryption/targets.rs +++ b/packages/eql/crates/eql-bindings/src/encryption/targets.rs @@ -333,19 +333,28 @@ pub enum TargetError { }, /// The stored bytes do not parse as the type: not JSON, not this /// domain's shape, or another EQL version. - #[error("stored value is not a {target}: {source}")] + /// + /// The message and `Debug` give the parser's error by kind, line and + /// column only. The parser's own message can quote the input it + /// refused, and the input is stored ciphertext. + #[error( + "stored value is not a {target}: {}", + stack_encrypt::diagnostic::describe_json_error(source) + )] Stored { /// The type the bytes were read as. target: &'static str, - /// What the parser refused. + /// What the parser refused. Its own `Display` and `Debug` can quote + /// the stored bytes, so do not print it. #[source] source: serde_json::Error, }, } /// The derived form, except that [`TargetError::Context`]'s label is shown -/// as ``. A `Debug` of an error reaches logs through `unwrap` and -/// `{:?}`, so it keeps the rule the message keeps. +/// as ``, and [`TargetError::Stored`]'s parser error by kind, line +/// and column only. A `Debug` of an error reaches logs through `unwrap` and +/// `{:?}`, so it keeps the rules the message keeps. impl fmt::Debug for TargetError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { @@ -387,7 +396,10 @@ impl fmt::Debug for TargetError { Self::Stored { target, source } => f .debug_struct("Stored") .field("target", target) - .field("source", source) + .field( + "source", + &stack_encrypt::diagnostic::describe_json_error(source), + ) .finish(), } } @@ -1102,6 +1114,30 @@ mod tests { assert_eq!(format!("{error:?}"), "Context { label: }"); } + /// The parser's own message quotes the string it refused, and that + /// string is stored ciphertext: the message and `Debug` give the kind, + /// line and column only. + #[test] + fn a_stored_refusal_quotes_none_of_the_stored_value() { + let source = serde_json::from_str::(r#""marker-ciphertext""#).unwrap_err(); + assert!(source.to_string().contains("marker"), "{source}"); + let error = TargetError::Stored { + target: "TextEq", + source, + }; + for text in [error.to_string(), format!("{error:?}")] { + assert!(!text.contains("marker"), "the stored value leaked: {text}"); + } + assert_eq!( + error.to_string(), + "stored value is not a TextEq: unexpected data at line 1 column 19" + ); + assert_eq!( + format!("{error:?}"), + "Stored { target: \"TextEq\", source: \"unexpected data at line 1 column 19\" }" + ); + } + /// The hand-written `Debug` keeps the derived form for the variants that /// carry no context. #[test] diff --git a/packages/eql/tests/encryption/tests/targets.rs b/packages/eql/tests/encryption/tests/targets.rs index daed05b0a..f5361760e 100644 --- a/packages/eql/tests/encryption/tests/targets.rs +++ b/packages/eql/tests/encryption/tests/targets.rs @@ -343,17 +343,23 @@ mod given_text_eq { let as_v3 = serde_json::to_vec(&payload).unwrap(); let error = refused(targets::decrypt("TextEq", &cipher, &email(), &as_v3)); + let TargetError::Stored { + target: "TextEq", + source, + } = &error + else { + panic!("{error}"); + }; + // The parser's error names the version it refused. The message + // gives the parser's error by kind and position only, because the + // parser's own text can quote the stored bytes. + assert!(source.to_string().contains("version 3"), "{source}"); assert!( - matches!( - error, - TargetError::Stored { - target: "TextEq", - .. - } - ), + error + .to_string() + .starts_with("stored value is not a TextEq: "), "{error}" ); - assert!(error.to_string().contains("version 3"), "{error}"); } #[tokio::test]