A Postgres database where the private columns are locked to each user.
Mark the columns that hold personal data as locked. They’re encrypted on the user’s device, so the database, its backups, your servers and anyone who breaches them see only ciphertext. Everything else is ordinary Postgres.
The hosted service is invite-only and not open to everyone yet: signing up needs an invite code. Self-hosting works today. How hosting works · Quickstart
notes table. title is readable. body and mood are locked: only the row’s owner can read them.What a leak exposes
Row-level security decides who may ask for a row. It does nothing once someone has the data itself. Locked columns stay ciphertext wherever the data ends up.
| If this leaks | Plain Postgres | Haystash DB locked |
|---|---|---|
| A copy of the database, or a backup | Everything is readable | Ciphertext in locked columns |
| A mistake in your access rules | Other users’ rows leak | Ciphertext in locked columns |
| The server, or whoever runs it | Reads everything | Reads everything but locked columns |
Columns you don’t lock stay as readable as in any Postgres. That is the trade: locked columns can’t be searched or sorted by the server, so you lock only what needs it.
How it works
-
Lock a column in the console
Press Lock on a column. A dry run shows first what will happen to each existing row and what blocks the lock. Nothing changes until you type the column’s name to confirm.
-
Your app uses the JS client
Reads and writes go through the client, as with any database API. It encrypts locked columns on the user’s device before anything is sent, and decrypts them when they come back. Your app sees plain values.
-
A key needs two parts
A user’s key opens only with their device (or recovery code, or passkey) together with the server’s Key Gate. Neither opens it alone. And Postgres itself refuses plaintext in a locked column, even from the table’s owner.
It reads like any database client
Sign a user in, then insert and select rows. The client handles keys, devices and encryption. Locked columns come back as plain values, like any other column.
pinned makes the client refuse to run if the server ever claims notes.body isn’t locked.
import { createClient } from '@haystash/db'
const db = await createClient('https://db.example.com',
{ pinned: ['notes.body'] })
const up = await db.auth.signUp({
email: 'ada@example.com', password: '…' })
showOnce(up.data.recoveryCode)
await db.from('notes').insert({
title: 'Monday', body: 'only I can read this' })
const { data } = await db.from('notes')
.select('title, body')
// the app sees: body: 'only I can read this'
// Postgres has: body: 'hs1.k.1._qmrOe7KdCJc…'
What fits, and what doesn’t
A column fits if only the row’s owner ever needs to read it, and your server never needs to filter, sort, search, join or process it.
Lock these
- A user’s private notes or journal
- A health log
- Saved addresses
- Settings only that user sees
Leave these readable, for now
- Email addresses used for sign-in or lookups
- Anything a backend job, webhook, moderator or admin reads
- Values two users share, such as messages
- Balances or counts the server computes
- Anything you search
Bring your existing app
- Import your data from Postgres or MongoDB with the
haystashcommand-line tool. It only reads your old database. - Users keep their passwords. Their bcrypt or Argon2 hashes come with them, and their first sign-in makes their keys.
- Or keep your own sign-in. After your login check, your backend asks for a one-time ticket, and the browser signs in with it.
- Lock columns on live data. Each value is sealed as soon as its owner has keys. Values of users who haven’t signed in yet wait, still readable, until they do or until you purge them.
The console
Tables, locks, users and devices, in one place that comes with the server.
The overview: which columns are locked, and since when.
The dry run: what happens to each row before anything changes.
What the database holds: rows exactly as a backup would see them.
The limits, plainly
Read these before you trust it with anything. The security docs list every known limit.
- It’s a prototype. Nobody outside the project has reviewed the code. Don’t put production data in it yet.
- The server can’t search locked columns. No filtering, sorting, indexing or joining on them.
- Your app’s code runs with the user’s keys. A malicious app update can read what the user can. So can a server that serves altered client code, if your app loads the client from it: bundle the client with your app.
- Locked means private, not tamper-proof. A compromised server can’t read a locked value, but it can replace one.
- Lost every way in means lost data. If a user loses every device, every passkey and their recovery code, their locked values are gone. Nobody can get them back.