Repository navigation
Description
Versions
@powersync/web2.4.2,@powersync/common2.3.1@journeyapps/wa-sqlite2.0.6 (mc-wa-sqlite.mjs),sqlite3mc_version()= 2.3.3, SQLite 3.53.0, default cipherchacha20- Chromium 156 (headless, Playwright 1.64), Windows 11
What happens
On a database stored with OPFSCoopSyncVFS and opened with the SQLite3MultipleCiphers build, PRAGMA rekey returns ok. From then on, no key opens the file: neither the old key nor the new key, and neither the empty key nor a plain build. Each open fails with file is not a database. The data is lost, and nothing reports an error.
The same steps on IDBBatchAtomicVFS (with mc-wa-sqlite-async.mjs) work as expected.
| Case | OPFS (OPFSCoopSyncVFS) |
IndexedDB (IDBBatchAtomicVFS) |
|---|---|---|
Plain file → encrypted (PRAGMA rekey = '<key>' with the cipher build) |
Reports ok; the file can then never be opened |
Works |
Change the key of a database PowerSync created encrypted (PRAGMA rekey = '<new>' on PowerSync's own connection) |
Reports ok; neither the old nor the new key opens it |
Works (old key refused, new key opens) |
Encrypted → plain (PRAGMA rekey = '') |
Not reachable | Works |
VACUUM INTO 'file:copy.db?key=…' or ATTACH … KEY … as a workaround |
unable to open database / database is locked |
Both work |
It doesn't depend on temp_store (MEMORY, as PowerSync sets it, or DEFAULT) or on size (5 rows or 2,000 rows). The journal mode is delete. A database created encrypted on OPFS from the start opens fine in a new worker and in PowerSync, so the harness itself is sound.
Steps to reproduce (key change, PowerSync only)
- Create a
PowerSyncDatabasewithdatabase: { dbFilename: 'rekey-test.db', vfs: 'OPFSCoopSyncVFS', encryptionKey: "x'<64 hex>'" }and write a few rows. - Run
PRAGMA rekey = "x'<other 64 hex>'"throughdb.execute. It returnsok. - Close the database and open it again with the new key, then with the old key. Both fail with
file is not a database.
A standalone reproduction (a Playwright runner, a page, and a raw wa-sqlite worker that does the plain → encrypted case without PowerSync) is in our spike: tools/spikes/web-encryption/ (node tools/spikes/web-encryption/run.mjs --only=rekeySelfTest,rekey; see its README). We can share it as a gist.
Expected
Either PRAGMA rekey works on OPFS as it does on IndexedDB, or it fails with an error and leaves the file readable. A silent ok that loses the database is the dangerous part.
Also noticed (may deserve separate issues):
- A top-level
encryptionKeyonPowerSyncDatabaseoptions is silently ignored, and the file stays plain. Onlydatabase.encryptionKeytakes effect. The README example could mislead. - In IndexedDB multi-tab mode, the shared worker hands an already-open connection to a second tab without checking that tab's
encryptionKey. A tab with a wrong key, or with no key, can read everything. On OPFS, such a tab is refused.
Activity