From v6.0 to v6.5.0: everything I changed in my post-quantum messenger
A month ago I wrote my first article about chat-app — a Persian web messenger with an original post-quantum protocol, PQ-MPRBA: a hybrid ML-KEM-768 + ECDH P-256 ratchet, ML-DSA-65 identity signatures, and Ristretto255-VOPRF blinded authentication, all running in the browser.
That was v6.0. Since then, the app has been through a line-by-line security review, five releases, and a database migration. This is the detailed version of all of it — every change, why it happened, and what it cost. No summary, no hand-waving.
⭐ Source: https://github.com/indirect-b/chat-app
🚀 Live demo: https://chatapp-server-1i2a.onrender.com
📦 Latest release: https://github.com/indirect-b/chat-app/releases/tag/v6.5.0
First: the security review (14 findings)
Before adding a single feature, I reviewed the v6.0 code line by line, against the implementation's own security claims. The review covered the crypto engine, the VOPRF endpoint, the public-key directory, the group epoch flow, and the crypto call sites in the UI. It found 14 findings. All 14 were fixed, with 14 tests and 108 assertions to prove it.
The worst ones:
F1 — identity private keys were derived from the username alone. The master seed was an HKDF over the username with public constants. Usernames are public in this app. That meant anyone who knew a username — and anyone who could read the public source — could recompute that user's ECDH private key, ML-KEM-768 secret key, and ML-DSA-65 signing key. Confidentiality, authentication, and forward secrecy, all void at once. The fix: all keypairs are now generated from the platform CSPRNG with no seed, and the deterministic derivation code was deleted. Losing the stored keys now means a new identity — the peer sees a safety-number CHANGED warning, which is the correct behaviour.
F5 — encryption failure silently sent plaintext. If encryption failed, the message was sent unencrypted anyway. Now encryption failure throws and the send aborts. Fail closed, always.
F3 — group epoch keys were derivable from public inputs. The server could compute group keys from values it already knew. Now every epoch key is a random 32-byte key, distributed per member with ML-KEM-768 encapsulation, and the server only relays ciphertexts.
F4 — the default passphrase was a public constant. It was removed entirely. New secrets use 600,000 PBKDF2 iterations.
F2, F6, F7, F9, F10. Unauthenticated public-key publication and group creation now require a Bearer session token, and the token's username must match. Signatures are verified before decryption instead of after. Replay protection now rejects consumed ratchet steps and tracks seen group messages. The ratchet rotates after 50 sent messages. And raw ECDH bits are no longer used as an AES key — HKDF with a room-id salt and a domain-separated info string does that job now.
Two things were left as known residuals: keys still sat in localStorage as plaintext, and messages had no timestamps. Both were on the list for the next round.
The whitepaper was updated to v2.0 with the hardened design and published as a GitHub Release.
v6.1.0 — Hardening round 2
This round closed the residuals and hardened the platform around the protocol:
- Keys moved from localStorage to IndexedDB (v4 keystore). The ECDH P-256 key is now a non-extractable WebCrypto key. ML-KEM and ML-DSA keys are stored AES-GCM-wrapped, because WebCrypto has no native key objects for them yet — only the ECDH key gets the full non-extractable treatment. Legacy keys are discarded on upgrade, so old chats are unreadable after this version.
- Strict CSP. No
unsafe-inline, no unpinned CDN. Admin and error pages are self-hosted. - Real tests. NIST KAT vectors for ML-KEM-768 and ML-DSA-65, fuzz tests with 490+ malformed inputs (all fail closed), and a benchmark suite. 31/31 tests pass.
- Bale fallback. One-time recovery codes (128-bit, scrypt-hashed server-side, rate-limited), a Bale health probe, and
GET /api/health. - Docs. SECURITY.md, THREAT_MODEL.md, AUDIT_STATUS.md, DEPLOYMENT.md, CONTRIBUTING.md.
The most important part of this round wasn't a feature — it was the verification. The round-2 changes arrived as a fresh export, and that export had been built on the pre-round-1 code. It had silently reverted seven of the fixes from the security review: the auth checks, the epoch keys, the default passphrase, the replay tracking, the rotation, the HKDF derivation, and the VOPRF seed.
I caught it by diffing every changed file against the hardened code. All seven were restored, covered by new regression tests, and the suite went from 28 to 31 tests. The same diff also found a latent bug: group creation never sent its auth token, so it would have failed with a 401 against its own server. Fixed.
The lesson I took from it: never merge an import without diffing it against your own security fixes. The tests are the safety net, but only if you actually run them and read the diff.
v6.2.0 — Login without Bale
Until this version, the only way in was a Bale ID and a one-time code from a Bale bot. This release added two more doors, and fixed a hole in the one that existed:
- Email signup. A one-time code by email (Gmail SMTP, env-gated), with the same one-time recovery code at registration.
- Google Sign-In. The server verifies the Google ID token and creates the account atomically from the verified email. No client secret anywhere — token verification only needs the Client ID as the audience.
- A public privacy page (
/privacy, Persian first, then English), linked from the login screen. - Database hardening. Production SSL now verifies the database certificate instead of accepting any. Row Level Security is enabled on all 7 tables with app-only policies. A least-privilege
chatapprole replaces the superuser for the app's connection. And startup now tolerates DDL permission errors and probes table readability before falling back to local storage — so the app can never silently run on an empty local database while looking healthy. - A security fix I found while building this:
/api/registerused to let anyone register any Bale ID or email without proving ownership, and receive its one-time recovery code. Now it requires a verified code first, or it returns 403.
76/76 tests pass.
v6.3.0 — Media end-to-end encryption
Message text was end-to-end encrypted. Files were not. Photos, voice notes, and videos were uploaded raw, stored as plain base64, and served from a public /uploads route with no auth check at all. This release closed that gap completely:
- Files are encrypted with the room key before upload (
PQF1+ AES-256-GCM). The server only ever stores ciphertext. The message ratchet is untouched — the file key comes from stable per-room material, so encryption consumes no ratchet step. - Media links open only for logged-in members of that chat.
/api/mediarequires a session token and room membership. The public/uploadsroute is gone. Media from deleted messages is denied. Orphan media is denied. Avatars stay visible to logged-in users — public profile pictures by design, never anonymous. - Old media is access-controlled but not encrypted. The server never had the key, so it cannot retro-encrypt. Re-upload a file to encrypt it.
While verifying this, I audited the rest of the read paths and found the same class of hole in four more endpoints: GET /api/messages/:roomId returned a room's messages with no session check at all, and room IDs are guessable (a DM room is just the two sorted usernames). Same story for /api/groups, /api/contacts, POST /api/user/update, and POST /api/add-contact — anyone could read any room's messages or overwrite any user's profile. All of them now require a session and ownership, and every denied request returns the same 403 — whether the room doesn't exist or you're just not a member — so the endpoint never leaks whether a room exists.
123/123 tests pass.
One honest note: the 1:1 file key is ECDH-derived (classical). The post-quantum ratchet key is wiped on every rekey and can't serve as a stable file key. Group files use the ML-KEM-distributed epoch key instead.
v6.4.0 — Google-only login
This one was a decision, not a feature request. I removed the Bale and email login flows entirely and made Google Sign-In the only way in:
- Google Sign-In in redirect mode instead of a popup. The popup flow left mobile users staring at a blank page after picking their account — the return trip never reached the app. Redirect mode sends the whole page to Google and back. It works.
- The privacy page got a real UI — dark, RTL, Persian first, matching the app, still with no scripts and no external resources (page-specific CSP).
- Account deletion is now confirmed with the one-time recovery code instead of a Bale OTP — which also fixed deletion for Google users, for whom Bale OTP delivery was impossible.
- The recovery-code login stays as the fallback for anyone who loses Google access.
112/112 tests pass. The count went down from 123 because the deleted email flows took their tests with them — that's expected, not a regression.
The honest cost of this one: Bale users who never saved a recovery code are locked out. There is no self-service recovery for them. I knew that before merging, and I did it anyway, because the direction was decided. If you're one of them, the only way back is an admin-side database fix.
v6.5.0 — Google profile sync
The smallest release of the five, and the most visible one. The name and photo from the Google profile now become the user's chat profile at sign-in. Existing users get updated on their next Google login. And if the user edits their display name or photo in the profile settings, their own choice wins — sign-in will not overwrite it afterwards.
The photo loads from lh3.googleusercontent.com, the only new image host allowed in the CSP. Other external avatar URLs are not loaded.
142/142 tests pass.
A side benefit worth mentioning: the avatar component used to send the session Bearer token to any avatar URL it fetched. Now only the pinned Google host loads directly, and anything else renders nothing.
The database move
While all of this was happening, the database itself moved house. Render's free PostgreSQL was expiring, so the app now runs on Supabase (Frankfurt, free tier). All 7 tables were copied with matching row counts — contacts 2, groups 1, media_blobs 2, messages 17, reports 0, settings 3, users 2 — primary keys restored, the hardening SQL applied (least-privilege role, RLS, app-only policies), and the app connects through the Supabase connection pooler. The old database is no longer used. Nothing was lost.
The tests, by the numbers
The test suite is the part I'm proudest of, because it's what caught the reverted fixes in v6.1.0. The count across the month:
14 → 31 → 43 → 57 → 65 → 76 → 100 → 111 → 123 → 112 → 142 The dip at v6.4.0 is the deleted email flows taking their tests with them. Every other step is a real gain — NIST vectors, fuzz tests, regression tests for each restored fix, access-control tests for every gated endpoint.
What's still honest
- The protocol is experimental and has not been independently audited. That hasn't changed, and I won't pretend otherwise.
- The 1:1 file key is ECDH-derived (classical). Group files use the ML-KEM epoch key.
- Old media is access-controlled, not encrypted. A member can still re-share a decrypted file outside the app.
- Bale users without a saved recovery code are locked out after the Google-only switch.
- Multi-device sync is documented, not implemented.
What's next: independent review of the protocol, live two-client tests for groups and media, and eventually a native app. The web app is the showcase — the protocol is the point.
If you're a cryptographer, the core is in src/utils/crypto.ts, the whitepaper is in the releases, and the changelog above is the whole story of the last month. Tell me what breaks. That's how it gets better.
