Ankit Sinha

Field note / 03

Verify passphrases before consuming a view

Two viewers racing for the last read—or one script guessing passphrases—will break a self-destructing note store unless verification runs before consumption inside a conditional SQL gate.

Nov 2026 · 3 min read · from GateKeep

Gate ordering matters #

When a link caps out after one view, the intuitive implementation reads the note row, decrypts or checks the passphrase in memory, and decrements the counter at the end. Under concurrent requests, two callers both read views_left = 1 and both unlock the payload.

Flipping the mistake naively—decrementing views_left up front—introduces a worse bug: anyone sending bad guesses can intentionally burn every remaining view before the real recipient opens the link.

GET /notes/:id
  └─ exists ─▶ not burned ─▶ not expired ─▶ verify passphrase ─▶ conditional UPDATE (views_left > 0)
                                                                     └─ last read ─▶ erase ciphertext + queue HMAC webhook

Files and webhooks follow the lock #

If a wrong passphrase can mutate the counter, an unauthenticated loop can destroy every unread secret without reading a single byte.