Skip to content
Trapdoor·Lab

Your account — how we store your progress

1Toy

A key the server does not have

An account on this site is optional and has no password — you sign in with a passkey. Your progress, the list of stations, Museum exhibits and use cases you visited and of stations you marked “I know this”, is encrypted by your browser before anything is sent. This is envelope encryption with your passkey playing the KMS: a random 256-bit data key (DEK) encrypts the progress with AES-GCM, and the server holds only its wrap — the DEK encrypted under a KEK that the browser derives with HKDF from the output of the passkey’s PRF extension (WebAuthn L3, §10.1.4). PRF is a pseudo-random function bound to the passkey: for the same input it always gives the same 32 bytes, and without the passkey nobody can compute them. Every passkey of the account has its own wrap of the same DEK, and the optional recovery code one more.

Below is your account as the server sees it — read live from GET /api/account/keys and /progress — next to what only this browser knows. Without an account the toy computes an example account here, with the same algorithms. It is also the only place where you manage the account’s key: create a recovery code, add a new device’s passkey, or delete the account.

What really sits in the database

On the left your account and the operations on its key; on the right what the server stores and the key chain that opens it — with real bytes wherever they may be shown.

Checking whether you are signed in…

The PRF output has high entropy, so HKDF is enough — the Argon2id of the Password hashing station is needed only for passwords. The recovery code is 160 random bits written as 32 characters, so it goes through HKDF too. The labels in the HKDF info and in the wrap’s AAD say what the key is for and in which version, so a wrap moved from the code’s drawer into a passkey’s drawer will not open. The data key lives in the browser as a non-extractable CryptoKey in IndexedDB (the WebCrypto station); an extractable one exists only inside the operation that makes a new wrap. That is why a new code or a new passkey needs the key opened once more — by touching a passkey or with the code. A passkey operation does not sign in: the browser draws the challenge, and the AES-GCM tag of the wrap decides.

The session lives in the __Host-tl-session cookie. It is HttpOnly, so document.cookie does not show it, and the browser accepts the __Host- prefix only with Secure, Path=/ and no Domain (MDN), so the cookie goes to this host alone. It opens the account, not the progress: whoever steals it reads ciphertext, not your list of stations.

2Break it

Someone stole the database

Assume the worst: someone has a copy of this site’s database, that is everything the server stores about the account. You can even take your own account’s rows into the attack. The server-breach attack is “resistant” in the graph: without the PRF output there is no KEK, without the KEK no data key, and nobody guesses 256 random bits. The toy really guesses and measures the rate, extrapolates the rest — and says so.

A stolen database

You are on the attacker’s side: you have a copy of the account tables — everything the server stores about the account. You send nothing; every attempt runs in this browser.

A copy of the database means the data key’s wraps and the progress ciphertext. See what can be pulled out of them and what cannot.

example computed in this browser

Read-only GET /api/account/keys and /progress — exactly what the server has in its database. The page writes nothing and sends no altered data.

Preparing an example copy of the database…

That word has limits. Encryption does not hide metadata: how many passkeys there are and when they were added, whether there is a recovery code, the ciphertext size — and from it, roughly, the number of visited stations, exhibits and use cases and of marked stations — or the number of writes. It does not protect against a server that serves an older revision: AES-GCM binds bytes to a key, not to a time. And it does not protect against whoever takes over the site’s server itself: the code that encrypts comes from the same domain, so swapped JavaScript would catch the PRF output at the next sign-in. On the Passkeys page, where that output appears at registration and sign-in, someone else’s code runs on every visit too: the Cloudflare Turnstile script from challenges.cloudflare.com, loaded without SRI, in the same JavaScript realm — there you trust Cloudflare as well. Encrypting in the browser protects against a database leak and a curious database admin; how the browser guards the site’s own code, and this one exception, is the subject of How this site protects you.

3In the real world

User-held keys in the world

  • BitwardenA passkey with the PRF extension not only signs in to Bitwarden but also unlocks the vault without the master password — as long as both the browser and the authenticator support PRF. Encryption has to be set up for each passkey separately; without PRF the vault still unlocks with the master password or a PIN.Source (Bitwarden)
  • LastPass (2022)In December 2022 LastPass said the attacker had copied a backup of customer vaults. Usernames, passwords and notes were encrypted with AES-256 under a key from the master password (PBKDF2, 100,100 iterations), but website URLs were stored in plain text, and customers with weaker master passwords were advised to consider changing their stored passwords.Source (LastPass (2022))
  • WhatsApp (2021)End-to-end encrypted chat backups are encrypted under a random key that users protect themselves: with a 64-digit key or a password. A password-protected key sits in an HSM-based vault that locks it for good after a limited number of failed attempts; neither WhatsApp nor the cloud provider can access the backup or the key.Source (WhatsApp (2021))
  • Apple — Advanced Data ProtectionTurned on, it raises the number of iCloud data categories under end-to-end encryption to 25, with keys held only by trusted devices. A recovery contact or recovery key has to be set up first, because Apple cannot help recover the data. Some metadata, such as file modification dates and checksums, stays under standard protection.Source (Apple — Advanced Data Protection)
  • 1Password — Secret KeyBesides the account password, 1Password uses a Secret Key: 128 bits of entropy, created on your device and never sent to the company. A brute-force attack on data from 1Password’s servers gets nowhere without it — the same reason this site’s recovery code is random bits, not a password.Source (1Password — Secret Key)
4Take it to your project

Client-side encryption in your service

Good practice

Encrypt user data under a random data key and keep only its wraps on the server: one per passkey (KEK = HKDF of the PRF output) and optionally one from a recovery code with at least 128 random bits. Separate the roles with a label in the HKDF info and in the AAD, each with a version number. Keep the PRF output in the browser, and store the data key as a non-extractable CryptoKey. Number writes with a revision and refuse an older one (409): the server cannot merge ciphertext, so the client merges.

JavaScript
const enc = new TextEncoder();
// KEK from the PRF output: HKDF, salt = 32 zero bytes, a label with role and version
const ikm = await crypto.subtle.importKey('raw', prfOutput, 'HKDF', false, ['deriveKey']);
const kek = await crypto.subtle.deriveKey(
  { name: 'HKDF', hash: 'SHA-256', salt: new Uint8Array(32), info: enc.encode('app kek passkey v1') },
  ikm, { name: 'AES-GCM', length: 256 }, false, ['wrapKey', 'unwrapKey']);
// a random data key, wrapped for this passkey
const dek = await crypto.subtle.generateKey({ name: 'AES-GCM', length: 256 }, true, ['encrypt', 'decrypt']);
const iv = crypto.getRandomValues(new Uint8Array(12));
const wrapped = await crypto.subtle.wrapKey('raw', dek, kek,
  { name: 'AES-GCM', iv, additionalData: enc.encode('app wrap passkey v1') });
// to the server: iv ‖ wrapped (60 B) — never prfOutput or dek
C#
// The server stores blobs and guards the revision: it neither reads nor merges them.
var updated = await db.Progress
    .Where(p => p.UserId == userId && p.Revision == request.Revision)
    .ExecuteUpdateAsync(s => s
        .SetProperty(p => p.Ciphertext, ciphertext)
        .SetProperty(p => p.Nonce, nonce)
        .SetProperty(p => p.Revision, request.Revision + 1));
return updated == 1 ? Results.Ok(new { revision = request.Revision + 1 }) : Results.Conflict();
Anti-pattern

Do not use one passkey’s PRF output as the data key itself: a second passkey gives a different output, and losing the passkey loses the data. Do not send the PRF output or the key to the server, not even “for convenience” — the server then knows the key and the encryption is decoration. Do not derive a key with HKDF from a password or a short code: HKDF does not slow guessing down. Do not keep the data key in localStorage, and do not let the last write win.

JavaScript
// ✕ data key = one passkey's PRF: a second device cannot recreate it
const dek = await crypto.subtle.importKey('raw', prfOutput, 'AES-GCM', false, ['encrypt']);

// ✕ the PRF output on the server: the server knows the key
await fetch('/api/keys', { method: 'PUT', body: JSON.stringify({ prf: [...prfOutput] }) });

// ✕ the key in localStorage: any script on the page reads it
localStorage.setItem('dek', JSON.stringify(await crypto.subtle.exportKey('jwk', dek)));
C#
// ✕ the last write wins: the second device overwrites the first one's visits
row.Ciphertext = request.Ciphertext;
await db.SaveChangesAsync();