Threat model: sync
SyncEngine moves records between the user’s devices as the contract in spec/openapi.yaml
defines: each write sealed under a fresh DEK, the DEK sealed under the AEK, both bound to the record by the AAD
conseal-sync:v1:<collectionId>:<recordId>.
6.1 What the envelope stops
Section titled “6.1 What the envelope stops”- Reading. Without the AEK the server can’t open a DEK, and without a DEK it can’t open a record or a blob.
- Forging. AES-GCM authenticates every record and blob. A ciphertext the server makes up, or alters by a bit, fails to unseal, and the client treats it as a bad record rather than data.
- Moving. The AAD names the collection and the record, and for a blob the blob too. A ciphertext copied to another record, collection or blob path fails to unseal there. The wrapped DEK carries the same AAD, so it can’t be paired with another record’s ciphertext either.
- Forged cursors. A cursor is signed by the server and tied to one user and collection, so a client can’t build one to skip through the order, or reuse one across collections.
6.2 What SyncEngine enforces
Section titled “6.2 What SyncEngine enforces”- Nothing in the clear but the contract’s fields. A push carries the record id, the server’s version and the
three envelope fields. No clock, timestamp, device id or field name travels outside the ciphertext. The
schemaVersionis sealed inside it. - Local-only fields stay local. Fields a collection lists as
localOnlyare removed before sealing, and kept from this device’s copy on every merge, so another device’s value never replaces them. - Ids that tell nothing.
saverefuses any id but a lowercase random UUID, so an app can’t use a provider’s file id, or a time-ordered UUID, as a record id the server sees. - A record opens only where it was sealed. The engine opens every pulled record and every conflict’s current
record under its own collection and id. A ciphertext the server altered, moved from another record or collection,
or that another AEK sealed, fails to open: the engine skips it, reports it as
unreadable, and applies the rest. - A conflict is a merge. A
409’s current record is checked to be the record pushed, opened, and merged with the local copy by the collection’s policy on plaintext; the result is sealed afresh, under a new DEK, and pushed against the current version. A push that conflicts again goes again, up to three rounds per sync, so a server that answers every push with a conflict costs three requests a sync rather than a loop. - An unreadable conflict isn’t overwritten. When a conflict’s current record doesn’t open, the engine has nothing
to merge with. It stops retrying that record (
unreadable_conflict) rather than push over it: if the fault is this device’s, such as a wrong key, overwriting would destroy what another device wrote. - Permanent failures stop. A
400or a413, or a record overmaxRecordBytesbefore it’s sent, stops that record’s retries until the app changes it, and is reported asrejected. Transient failures leave it pending for the next sync. - Only the server’s cursor. The engine resumes pulls from the cursor the server last gave it, never from its own clock. A cursor the server refuses means starting from the beginning, which merges idempotently: a pulled record whose version this device already holds is skipped.
- No lost edits. Every write to the local store is a compare-and-set on the record’s
rev, so a pull or a push result never overwrites a change the app made while it was in flight.
6.3 What a dishonest server can still do
Section titled “6.3 What a dishonest server can still do”A server that breaks the contract can’t read or forge, but it controls which genuine ciphertexts a client gets:
- Roll back. It can serve an older ciphertext of a record in place of the newest. The old one is genuine, so it unseals. A device that already holds the newer state keeps it if its merge policy compares versions inside the plaintext, as a field-level clock does; a last-write-wins policy, or a device syncing for the first time, takes the old one.
- Withhold. It can leave records out of a pull, or skip a range of
seq, and the client can’t tell a missing record from one never written. - Fork. It can show two devices different histories, so they diverge without seeing a conflict.
- Destroy. It can delete records, or answer every push with a conflict so nothing is ever written.
Detecting these needs state the server doesn’t control, such as per-device counters signed inside the plaintext. That is not part of this version. Against an honest server they don’t arise: the contract’s ordering rules exist so that an honest server gives every device the same complete history.
6.4 Replay
Section titled “6.4 Replay”- A replayed request gains nothing. TLS stops a network attacker capturing one, and a replayed push names a
baseVersionthat is no longer current, so it gets a409instead of overwriting newer data. - A replayed cursor only reads again from an earlier point, of the caller’s own data.
- A replayed record is the rollback in §6.3: only the server can do it, and the envelope doesn’t stop it.
6.5 The conflict path
Section titled “6.5 The conflict path”A 409 returns the server’s current record so the client can merge. The merge runs on the client, on plaintext the
client has unsealed itself. So a conflict can’t make a client accept content the server made: current must unseal
under the record’s AAD like any other record, and the client checks that current.id is the id it pushed. What a
dishonest server can do through a conflict is the same as §6.3: hand back a stale current (rollback), or answer
409 forever (destroy). A client that loops on conflicts for the same record should back off rather than spin, as
SyncEngine does after three rounds.
A client that counted a 409 as a failure would stop syncing a record edited on two devices at once, for good and
without a word. So the contract makes a 409 a merge instruction, and keeps permanent failure for 400 and 413.
6.6 Deletes
Section titled “6.6 Deletes”A tombstone drops the record’s ciphertext, and the server deletes the record’s blobs. The client can’t check that the server, its backups or its storage provider really erased them: a deleted record is unreadable without the AEK, not proven gone.
6.7 What it relies on
Section titled “6.7 What it relies on”- The merge policy. Every remote change to a record this device holds goes through the collection’s policy,
pending or not, with
pendingsaying which. A policy that compares versions inside the plaintext, such as a field-level clock, keeps the newer value when a dishonest server serves a stale one, and the engine pushes it back. The built-inlastWriteWinscompares nothing: with no change pending, it takes the server’s value, stale or not. Pick it for data where that’s acceptable. - Plaintext at rest. Records are plaintext in the app’s
RecordStore, by design: queries, indexes and merges run on them, and encryption happens at the network boundary. Anything that can read the app’s storage reads the records. - The
Keyring. The engine asks it for the AEK at the start of every sync and holds the AEK only for that sync. A lockedKeyringstops the sync before anything is sent. - One engine per store. The compare-and-set protects writes from the app and the engine, and from two engines
sharing one store. Two
synccalls on one engine share a run; two engines syncing one store at once, such as two tabs, can push the same change twice, which the server answers with a conflict that merges to the same value.