Background
When the Go SDK (languages/golang) encrypts a field, it binds a context into the ciphertext: the table, the column and any extension the cipher adds (Cipher.Extend, for example a tenant ID). A ciphertext opens only under the same context.
Problem
Nothing in the context names the row. Someone who can write to the database can copy a sealed value from one row to another row of the same table, and Decrypt returns it as part of the other row, with no error. For example, one user's email can appear on another user's row.
A reviewer did this for #1094: they swapped the Email fields of two rows from testusers.Encrypt, and Decrypt returned each email in the other row.
The Rust engine can prevent this. Its plan builder has context_field (packages/stack-encrypt/src/plan/build.rs), which reads part of the context from a field of each record, such as its id. No stash tag spells it, so a Go program cannot use it.
The Go README now warns about this ("Take care" note in "The cipher"), so the gap is documented. It is not closed.
Proposal
- Add a struct tag that spells
context_field. For example, _ struct{} `stash:"context=users,row=id"` binds every field to the row's id.
- Test it: swap one field between two rows and check that
Decrypt fails.
- Remove the "Take care" note from the README once the tag ships.
Found in the review of #1094.
Background
When the Go SDK (
languages/golang) encrypts a field, it binds a context into the ciphertext: the table, the column and any extension the cipher adds (Cipher.Extend, for example a tenant ID). A ciphertext opens only under the same context.Problem
Nothing in the context names the row. Someone who can write to the database can copy a sealed value from one row to another row of the same table, and
Decryptreturns it as part of the other row, with no error. For example, one user's email can appear on another user's row.A reviewer did this for #1094: they swapped the
Emailfields of two rows fromtestusers.Encrypt, andDecryptreturned each email in the other row.The Rust engine can prevent this. Its plan builder has
context_field(packages/stack-encrypt/src/plan/build.rs), which reads part of the context from a field of each record, such as itsid. Nostashtag spells it, so a Go program cannot use it.The Go README now warns about this ("Take care" note in "The cipher"), so the gap is documented. It is not closed.
Proposal
context_field. For example,_ struct{} `stash:"context=users,row=id"`binds every field to the row'sid.Decryptfails.Found in the review of #1094.