Skip to content

docs(golang): say a query through a cipher with a binding is refused - #1922

Open
auxesis wants to merge 3 commits into
nextfrom
docs/go-binding-query
Open

auxesis wants to merge 3 commits into
nextfrom
docs/go-binding-query

Conversation

@auxesis

@auxesis auxesis commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The Go SDK's encrypt README now says that a query through a cipher with a binding is refused with ErrEncoding. A binding (cipher.Bind(rowID)) ties a stored value to its row. The README told readers to query "through a cipher with the same scope". It did not say what happens through a cipher with a binding, so readers took the query as accepted.

Changes

  • languages/golang/encrypt/README.md: the scope and binding list now says to query through a cipher with the same scope and no binding. It says that a query through a cipher with a binding is refused with ErrEncoding, for every query method. It also says to open the row the query finds through cipher.Scope(tenant).Bind(rowID).
  • languages/golang/cmd/stashgen/README.md: the paragraph on encrypt_into with a scope or a binding says the same, in shorter form. It had the same wording as the encrypt README.
  • languages/golang/CHANGELOG.md: an entry under [Unreleased], in "Fixed".

Why the query is refused

Cipher.queryPlan in languages/golang/encrypt/records.go returns ErrEncoding when the plan has a binding. The error says that a binding is in the stored context only, so a query by the scopes alone finds the row. Every generated query method calls Cipher.QueryTerm. That method goes through operandPlan and then queryPlan.

The reads of part of a JsonSearch document (Selector, Subtree, and Children) are the exception, because operandPlan drops the binding for them. The README's text about those reads was already right, so it is unchanged. The doc comments on Cipher.Bind and Cipher.QueryTerm already say the same.

Verification

  • Ran TestABindingIsInTheStoredContextOnly in encrypt/bindings_test.go over the deterministic test guest: it passed. That test checks that a bound QueryTerm returns ErrEncoding, and that the same query by the scope alone derives the stored term.
  • Wrote a throwaway test that calls the generated Eq method on an EQL TextEq field through Scope("tenant-42").Bind(uint64(9)), over the deterministic EQL guest. It returned cipherstash: malformed input: field "email": a query takes no binding; .... That error matches ErrEncoding. The same call through the scope alone succeeded. I deleted the test afterwards.
  • Ran the plain-language checker on the changed README lines and the changelog entry: no findings.
  • No Go code changed, so I did not run the full Go test suite, go vet, or golangci-lint.

Related

Closes #1862

🤖 Generated with Claude Code

https://claude.ai/code/session_01CtEQzxj55RUn35dkbhdwQk

Summary by CodeRabbit

  • Documentation
    • Clarified how row-level bindings affect opening encrypted values and why queries with a bound cipher are refused.
    • Added guidance on querying with the matching scope, then opening rows with their binding.
    • Explained how context-based encryption supports queries and how mismatched contexts affect opening values.

@auxesis auxesis added documentation Improvements or additions to documentation SDK Golang Pull requests that update Go code labels Nov 26, 2026
@changeset-bot

changeset-bot Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: d15d240

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

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

@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The Go encryption documentation now explains that queries through a cipher with a binding are refused with ErrEncoding. It describes querying with the same scope and no binding, then opening rows with the binding. It also clarifies context_field behavior and context mismatch errors.

Changes: Go encryption query and context guidance

Layer / File(s) Summary
Document bound-cipher query behavior
languages/golang/encrypt/README.md, languages/golang/cmd/stashgen/README.md, languages/golang/CHANGELOG.md
The READMEs state that bound-cipher queries are refused with ErrEncoding. They describe querying with the same scope and no binding, then opening rows with the matching binding. The stashgen README also states that EQL values record their table and column in i. The changelog records the query guidance correction.
Document context-based encryption and queries
languages/golang/encrypt/README.md, languages/golang/CHANGELOG.md
The README explains how context_field ties values to stored row contexts, how context mismatches are rejected, and that queries require a named context. The changelog records the context guidance update.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Other

Possibly related PRs

  • cipherstash/stack#1659: Describes Go generated readers that do not open documents sealed with bindings, which relates to the README’s bound-value read guidance.
  • cipherstash/stack#1591: Defines query-context behavior that rejects bindings in queries and derives search terms from scopes.

Suggested reviewers: freshtonic

Merge Risk: Minimal · up to d15d2

This is a documentation-only correction that makes the Go SDK guidance match actual behavior: queries through a bound cipher are refused, so queries should use the same scope without a binding. No runtime behavior changes, and merge risk is negligible.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "docs(golang): say a query through a cipher with a binding is refused" matches the main change. The PR updates the Go SDK encrypt and stashgen READMEs and the changelog to state that queryin…
Linked Issues check Passed Issue #1862 has one proposal: correct the Go SDK README so it no longer says a query through a cipher with a binding works. The reviewed head languages/golang/encrypt/README.md now states, in the vi…
Out of Scope Changes check Passed The PR changes three documentation files. languages/golang/encrypt/README.md is the file named in #1862. languages/golang/cmd/stashgen/README.md is the other user-doc page that the issue names, an…
Full details: Title check

Explanation

The title "docs(golang): say a query through a cipher with a binding is refused" matches the main change. The PR updates the Go SDK encrypt and stashgen READMEs and the changelog to state that querying through a bound cipher is refused with ErrEncoding, and that queries should use the same scope without a binding. The title is short, names the language scope, and states the primary behavior being documented.

Full details: Linked Issues check

Explanation

Issue #1862 has one proposal: correct the Go SDK README so it no longer says a query through a cipher with a binding works. The reviewed head languages/golang/encrypt/README.md now states, in the visible "Take care" section, that a cipher with a binding cannot query and that every query method refuses it with ErrEncoding. It tells readers to query through cipher.Scope(tenant) and then open each row with that row's binding. This matches the behavior in the issue. The code supports the README: the previous review confirmed that Cipher.queryPlan in languages/golang/encrypt/records.go returns ErrEncoding when the plan has a binding. The head encrypt README is truncated before its EQL-column scope and binding list, so the exact wording of that list is not read directly; it rests on the PR and raw summaries. The stashgen README changes (+4/-2) are also not readable directly; they rest on the PR description and raw summary. The issue's proposal is a documentation correction, so no code change is required.

Full details: Out of Scope Changes check

Explanation

The PR changes three documentation files. languages/golang/encrypt/README.md is the file named in #1862. languages/golang/cmd/stashgen/README.md is the other user-doc page that the issue names, and its change applies the same query-refusal correction to encrypt_into with a scope or binding. This supersedes the earlier finding that the stashgen README was unchanged; the current PR does change it. languages/golang/CHANGELOG.md adds a Fixed entry under [Unreleased] for the same correction. The revised "Take care" note on context_field and the binding trade-off is in the same section as the corrected binding text and describes the same behavior. No Go code changes are reported. No unrelated change is identified. The stashgen and encrypt README diffs could not be read directly, so the description of their exact text relies on the PR and raw summaries.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI; Enforced overrides: Organization
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c463ef2f-1ffb-4540-93ef-7b839b5a6b84
Commits

Reviewing files that changed from the base of the PR and between 436f322 and d15d240.

Files selected for processing: 3

  • languages/golang/CHANGELOG.md
  • languages/golang/cmd/stashgen/README.md
  • languages/golang/encrypt/README.md
Files skipped from review as they are similar to previous changes: 1

  • languages/golang/CHANGELOG.md

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

@auxesis
auxesis marked this pull request as ready for review November 26, 2026 14:54
@auxesis
auxesis requested a review from a team as a code owner November 26, 2026 14:54
@auxesis

auxesis commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor
Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@cipherstash-agent cipherstash-agent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review attestation

Reviewed 436f322 · posted from Claude Code · claude-opus-5-5 · effort medium
Sources: code-review · claude-opus-5-5; mattpocock-skills:code-review (Standards and Spec agents) · claude-opus-5-5; review-cross-check verifier · claude-opus-5-5
Skills: code-review, company-skills:rust-security (no Rust in the diff, so it had nothing to apply to), mattpocock-skills:code-review, company-skills:review-cross-check

Findings (3): 3 minor. 2 inline, 1 below.

  • languages/golang/cmd/stashgen/README.md:447 (outside diff) minor This line still says "query it through a cipher with the same scope", with cipher.Scope(tenant).Bind(rowID) as the example in the same sentence. A reader who queries through the bound cipher gets ErrEncoding from Cipher.queryPlan (encrypt/records.go:187-188). #1862 names this README as one of the user docs, and the CHANGELOG entry reads as if the problem is fixed. Use the new encrypt README wording here too.

The new README text matches the code. operandPlan exempts only Selector, Subtree and Children, and TestABindingIsInTheStoredContextOnly covers the refusal. CodeRabbit's review was still in progress when this was checked.


Generated by Claude Code

Comment thread languages/golang/CHANGELOG.md Resolved
Comment thread languages/golang/CHANGELOG.md Resolved
@auxesis

auxesis commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

The review's finding on languages/golang/cmd/stashgen/README.md:447 is fixed in 14c4482. That README now says to query through a cipher with the same scope and no binding, and that a query through a cipher with a binding is refused with ErrEncoding.

auxesis and others added 3 commits November 27, 2026 15:35
The encrypt README said to query a bound value through a cipher with the same scope, and did not say what happens through a cipher with a binding. Readers took that as accepted. Cipher.queryPlan refuses it with ErrEncoding, because a binding is in the stored context only and no query context holds it. The README now says so, and says to query through the scope alone, then open the row through the cipher with the binding.

Refs #1862

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01CtEQzxj55RUn35dkbhdwQk
The stashgen README gave cipher.Scope(tenant).Bind(rowID) as its example and then said to query through a cipher with the same scope, with no word about the refusal. Cipher.queryPlan refuses a query through a cipher with a binding with ErrEncoding. The README now says to query through the scope alone, and that the bound query is refused. The CHANGELOG entry now follows the file's form, cites the issue, and no longer says the old README called the query accepted.

Refs #1862

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01CtEQzxj55RUn35dkbhdwQk
…to tie a value to its row

The Take care note in the encrypt README said the context binds a value
to its table, its column and the cipher's extension, and offered only a
context_field to tie a value to its row. The context also binds any
bindings, and cipher.Scope(tenant).Bind(rowID) ties a value to its row ID.

The note now names both ways, and the trade-off: a cipher with a binding
cannot query, and a context_field can query within one context. It also
says that a context_field ties a value to its row's context, so a value
copied to another row with the same context decrypts there.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01CtEQzxj55RUn35dkbhdwQk
@auxesis
auxesis force-pushed the docs/go-binding-query branch from da14c41 to d15d240 Compare November 27, 2026 04:35
@auxesis

auxesis commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor
Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation Golang Pull requests that update Go code SDK

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Go SDK README: a query through a cipher with a binding is refused, not accepted

2 participants