Skip to content

Conseal is pre-release. The interface can change between releases.

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>.

  • 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.
  • 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 schemaVersion is sealed inside it.
  • Local-only fields stay local. Fields a collection lists as localOnly are 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. save refuses 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 400 or a 413, or a record over maxRecordBytes before it’s sent, stops that record’s retries until the app changes it, and is reported as rejected. 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.

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.

  • A replayed request gains nothing. TLS stops a network attacker capturing one, and a replayed push names a baseVersion that is no longer current, so it gets a 409 instead 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.

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.

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.

  • The merge policy. Every remote change to a record this device holds goes through the collection’s policy, pending or not, with pending saying 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-in lastWriteWins compares 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 locked Keyring stops 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 sync calls 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.
  • Detect withheld or forked history (§6.3).
  • Hide activity. Pushes happen when the app calls sync, a batch shows which records changed together, and record sizes aren’t padded (§10).
  • Rotate keys. A revoked device keeps the AEK it held, and every record sealed under it.