Lion Cipher Lab

Stop ciphertext swapping in field-level encryption by binding each value to its row with AEAD associated data

Why it matters

Teams encrypt the scary columns (social security numbers, bank accounts, roles, API tokens) and tick the 'encrypted at rest' box. Then someone with write access to the database, through SQL injection, a stolen backup, or an over-privileged admin, copies one encrypted value into another row. The app decrypts it perfectly, because the ciphertext is genuine. In this lab that one move makes an ordinary user an admin, redirects a payout to an attacker's account, and reads another user's SSN through the attacker's own profile page, all without the key. The fix is one argument most code leaves…

What you'll learn

Steps in this lab

  1. Field-level encryption and AEAD, in plain words
  2. The attacker who can write to your database but has no key
  3. Set up a workspace and install one library
  4. Read the toy app: one function decides everything
  5. Before: run it with no associated data
  6. The fix: bind each value to its key id, table, column and row
  7. Honest negative 1: binding does not stop rollback
  8. Honest negative 2: an attacker who can make the app encrypt
  9. Design the AAD well: what goes in, what stays out
  10. Nonces, usage limits and key rotation with a key id
  11. Where the key lives: envelope encryption and a KMS
  12. Searchable columns: why deterministic encryption leaks
  13. When to use this, when not to, and how a pro does it

Open the full interactive lab →