Repository navigation
Conversation
Client.Keyset(nil) returns a cipher that stores an ErrEncoding and is bound to the default keyset in the meantime. Every call that encrypts, decrypts or derives checks the stored error first, through Cipher.plan. KeysetID did not: it resolved the keyset straight away, so Keyset(nil).KeysetID returned the default keyset's id and no error. A program that validates a tenant's keyset at boot with KeysetID then believed it held a valid one. KeysetID now returns the stored error before it resolves anything. That covers a nil selector and any value Scope, Bind, Context or Audit refused. A new test calls every error-returning method on such ciphers and checks each returns the stored error before the guest is asked. Refs #1998 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CtEQzxj55RUn35dkbhdwQk
|
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
|
@coderabbitai review |
Action performed
|
cipherstash-agent
left a comment
There was a problem hiding this comment.
Review attestation
Reviewed b8ad961a · 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 agents) · claude-opus-5-5
Skills: code-review, mattpocock-skills:code-review, review-cross-check, rust-security (loaded; the diff has no Rust, so none of its rules applied)
Findings (2): 1 minor, 1 nit (pre-existing). 1 inline, 1 below.
languages/golang/encrypt/cipher.go:37-40(outside diff) minor The comment on theerrfield still says it holds "a refused extension part, context or audit value". The newKeysetIDdoc and the CHANGELOG entry say it also holds a nil selector fromClient.Keyset(nil)(client.go:457) and a binding thatBindrefused (cipher.go:104-105). Update it to name all of them, and sayScopeinstead of the deprecated aliasExtend.
The fix matches the guard in Cipher.plan, and the new test calls all eight *Cipher methods that return an error. The Fixed placement in the CHANGELOG matches earlier entries such as rc.3 and rc.5, so it is not flagged.
Generated by Claude Code
| // Client.Keyset(nil) fails with [ErrEncoding], and does not answer with the | ||
| // default keyset's id. | ||
| func (cph *Cipher) KeysetID(ctx context.Context) (KeysetID, error) { | ||
| if cph.err != nil { |
There was a problem hiding this comment.
nit · pre-existing Calling KeysetID on a nil *Cipher panics on cph.err. Open instead returns ErrEncoding (records.go:115-119). Before this PR it panicked on cph.client, and every other *Cipher method except Open panics the same way. Guard all of them, for example in copy and plan plus KeysetID and the accessors, or guard none; guarding KeysetID alone would be inconsistent.
Source: code-review · claude-opus-5-5; mattpocock-skills:code-review · claude-opus-5-5
Generated by Claude Code
Summary
In the Go SDK,
client.Keyset(nil).KeysetID(ctx)returned the default keyset's id and no error. A program that checks a tenant's keyset at boot withKeysetIDthen believed it held a valid keyset.KeysetIDnow returnsErrEncodingfor that cipher, as every other call through it already did.Changes
encrypt/cipher.go:Cipher.KeysetIDreturns the error the cipher stores before it resolves the keyset. That error is a nil selector, or a value thatScope,Bind,Context, orAuditrefused. Its doc comment says so.encrypt/cipher_error_test.go: a test that calls every method onCipherthat returns an error (KeysetID,Contexts,Seal,Open,QueryTerm,Verify,TargetLimit,JSONOpen) on ciphers with a stored error. Each must return that error before the guest is asked. A second test uses the deterministic test client to showKeyset(nil).KeysetIDno longer answers with the default keyset's id.CHANGELOG.md: an entry under[Unreleased],Fixed.The other methods already returned the stored error, through
Cipher.plan.KeysetIDwas the only one that skipped it.Verification
KeysetIDonKeyset(nil)returned00000000-0000-0000-0000-000000000000and a nil error. With the fix, both pass.mise run wasm:guest:build,wasm:guest:build:eql,wasm:guest:build:deterministic,wasm:guest:build:eql:deterministicandwasm:auth-guest:build.languages/golang:CGO_ENABLED=0 go test -timeout=25m ./...passed for every package.go vet ./...passed,gofmt -l .printed nothing, andgolangci-lint run ./...(2.14.0) reported 0 issues.Related
Closes #1998
🤖 Generated with Claude Code
https://claude.ai/code/session_01CtEQzxj55RUn35dkbhdwQk
Summary by CodeRabbit
Cipher.KeysetIDnow reports a stored cipher error when the cipher was created with a nil keyset selector, rather than returning the default keyset’s ID.