Skip to content

Go SDK: no struct tag binds a value to its row, so a value copied to another row decrypts there with no error #1123

Description

@coderdan

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

  1. Add a struct tag that spells context_field. For example, _ struct{} `stash:"context=users,row=id"` binds every field to the row's id.
  2. Test it: swap one field between two rows and check that Decrypt fails.
  3. Remove the "Take care" note from the README once the tag ships.

Found in the review of #1094.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions