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

The console's “What the database holds” tab for a notes table: id, owner, created_at and title are readable; the locked body and mood columns hold only ciphertext such as hs1.k.1.R57v7Y…
What Postgres stores for a 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 leaksPlain PostgresHaystash DB locked
A copy of the database, or a backupEverything is readableCiphertext in locked columns
A mistake in your access rulesOther users’ rows leakCiphertext in locked columns
The server, or whoever runs itReads everythingReads 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

  1. 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.

  2. 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.

  3. 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.

Try it in five minutes

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 haystash command-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.

Read the migration guide

The console's Columns tab: body is locking, with 3 values already ciphertext and 2 waiting for owners who have not signed in; mood is locked.
A column locking on live data: three values sealed, two waiting for their owner.

The console

Tables, locks, users and devices, in one place that comes with the server.

  • The console overview: two locked columns, one dropped, and a getting-started checklist.
    The overview: which columns are locked, and since when.
  • The lock dry run for notes.body: 3 values sealed now, 2 waiting, 0 empty, and what changes after locking.
    The dry run: what happens to each row before anything changes.
  • What the database holds: the locked columns of a notes table as ciphertext.
    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.