My app said it encrypted your data. It didn't.
From v0.8.0 until its last release, v0.13.1, Polyphon said it encrypted your data. The project page promised SQLCipher whole-database AES-256 encryption, and went further: “Every byte on disk is ciphertext,” and these were “verifiable properties of the code.”
Nobody verified them. Including me.
The database was never encrypted. Every release from v0.8.0 on wrote a plain SQLite file that any SQLite tool could open with no key at all.
How I found it
This week I updated Polyphon’s dependencies one last time before archiving it. The database driver is a native module, so I looked at how it was being built for Electron, and the build step didn’t look like it could do what it claimed. So I stopped assuming and checked the database on my own install.
How I confirmed it
I didn’t want to write this post from a theory, so I checked from three angles.
- My own install. The database written by v0.13.1 on my machine (the log
shows version 0.13.1 on Electron 41.0.3) starts with the 16 bytes
SQLite format 3\0, the header of an ordinary SQLite file. Python’s built-insqlite3module opens it with no key and reads every table. - The app’s own behavior. With real SQLCipher, setting a key and then querying a plaintext file fails with “file is not a database.” v0.13.1 set a key on that same plaintext file and opened it without complaint. That’s only possible if the key was ignored.
- The shipped DMG. In the released app bundle, the Electron build of the
driver contains zero
sqlcipherstrings and zerosqlite3_keyor codec symbols. A correctly built driver has 99sqlcipherstrings and 65 key and codec symbols.
What the app was supposed to do
Polyphon is an Electron app. It stores sessions, messages, and settings in
SQLite through better-sqlite3, a native Node module. The plan was to compile
that driver against SQLCipher instead of stock SQLite, generate a random 256-bit
key, and open the database like this:
const db = new Database(dbPath, { nativeBinding });
db.pragma(`key = "x'${keyHex}'"`);
db.pragma('kdf_iter = 1');
db.prepare('SELECT count(*) FROM sqlite_master').get();
logger.info('SQLCipher database initialized');(kdf_iter = 1 looks alarming, but it’s fine here: the key is already 256
random bits, not a passphrase, so there’s nothing to stretch.)
With SQLCipher, PRAGMA key sets the key, and the query on sqlite_master
proves the key works. If it’s wrong, that query fails with “file is not a
database.”
What it actually did
An Electron app can’t load a native module built for system Node; the ABIs differ. So the build produced two copies of the driver: one for Node, used by the tests, and one for Electron, used by the app. The Electron copy came from this line:
npx electron-rebuild -f -w better-sqlite3 --extra-args="--sqlite3=<sqlcipher dir>"That --extra-args flag was supposed to pass the SQLCipher source through to
the compiler. It did nothing. electron-rebuild found a prebuilt
better-sqlite3 binary for that Electron version, downloaded it, and never
compiled anything. The prebuilt binary is stock SQLite.
Stock SQLite doesn’t know PRAGMA key, and an unknown pragma isn’t an error in
SQLite; it’s silently ignored. So the key line did nothing, the sqlite_master
query succeeded against an ordinary unencrypted file, and the app logged
“SQLCipher database initialized.” Every step that was meant to prove encryption
passed, because none of them could fail.
The app even knew how to recognize an unencrypted database. On first launch it
checked the file header for SQLite format 3, to detect the pre-0.8.0 format.
But that check ran only once, before a sqlcipher-migrated-v1 sentinel file
was written. After that, nothing ever looked at the header again.
Why the tests didn’t catch it
There were encryption tests, and they tested the right things. They wrote a database to disk, checked the header wasn’t plaintext, confirmed a wrong key was rejected, and round-tripped data.
They ran under Vitest, in Node. So they loaded the Node build of the driver, which was compiled correctly with SQLCipher, and they passed. They were testing a sibling of the shipped binary, and nothing ever put the Electron build through the same checks.
The fix, and the trap inside it
The build fix is on main. The Electron driver is now compiled directly with
node-gyp against the Electron headers, so there’s no prebuilt to fall back to.
And the build fails if the output doesn’t contain SQLCipher:
function assertSqlcipher(binaryPath) {
if (!readFileSync(binaryPath).includes('sqlcipher')) {
console.error(`ERROR: ${binaryPath} was not linked against SQLCipher`);
process.exit(1);
}
}That’s a cheap tripwire, not proof: it shows a string is present, not that
encryption works. So I also checked the result in Electron itself (main has
since moved from Electron 41 to 44). PRAGMA cipher_version reports 4.14.0, the
file header is ciphertext, a test string written to the database appears
nowhere in the file’s bytes, and a wrong key is rejected.
The fix was never released, and it can’t simply be released. Every existing
user has a plaintext database plus that sqlcipher-migrated-v1 sentinel. A
correctly built app would see the sentinel, skip the legacy check, set a key on
the plaintext file, and fail with “file is not a database.” The app wouldn’t
start. Fixing the bug naively would turn a silent security failure into a loud
availability one.
A real release needs two things first. One is an in-place migration that
encrypts the existing file (ATTACH ... KEY plus sqlcipher_export). The other
is a startup guard that refuses to run if PRAGMA cipher_version comes back
empty. I haven’t added that guard to main, because without the migration it
would stop every existing install from starting. That’s exactly why it needed
to be there from the first encrypted release.
A second problem in the same build
While fixing the build I found something else. With npm’s default loglevel,
node-gyp ran at its most verbose setting, and at that level it prints the full
process environment, including any secrets in it. The driver was compiled in
a postinstall step, so every development install wrote the environment into
the install output. In CI, the install steps didn’t carry the signing or
publishing secrets, which were scoped to later steps. A developer’s shell is a
different story: Polyphon reads provider API keys from environment variables,
so anyone building it locally with those set had them printed to their
terminal and npm logs. The build now pins --loglevel=info.
What I’ve done about it
- Removed the false encryption claims from the site.
- Corrected the earlier posts, including the v0.8.0 release post that announced the feature.
- Added a security note to the README: releases through 0.13.1 don’t encrypt the database; treat it as plaintext and rely on FileVault.
- Archived the project, since no further releases are planned.
As far as I can tell, Polyphon had very few users. That’s lucky, and it doesn’t excuse anything. The claim was on the page, in plain words, from March to October.
What I’d do differently
Test the artifact you ship, not a sibling build. The tests were right about the binary they loaded. The bug lived in the gap between that binary and the one in the DMG. A test against the packaged app, or even a script that inspects the packaged driver, would have caught this on day one.
A security property needs a runtime assertion, not a log line. “SQLCipher
database initialized” was a statement, not a check. Refusing to start when
PRAGMA cipher_version is empty would have made the failure obvious the first
time anyone launched the app. If a property matters enough to advertise, it
matters enough to assert at startup.
“Verifiable” claims should actually be verified. I wrote that the encryption was a verifiable property of the code. It was verifiable. Somebody just had to open the shipped binary and look, and that somebody should have been me, before the claim went on the page.
If you advertise a security property in your own project, when did someone last check it against the binary your users actually run, not the one your tests load?