Reject unknown tables and columns from a sync peer
fix(sync): reject unknown tables and columns from a sync peer
Reject unknown tables and columns from a sync peer4ec300-fix-reject-unknown-tables-and-columns-from-cve-2026-135686fixreject unknown tables columns sync peer
Committed by eliandoran
commit message
fix(sync): reject unknown tables and columns from a sync peer
updateNormalEntity() passed the peer-supplied entityName and the keys
of the peer-supplied row straight to sql.replace(), which writes both
into the INSERT OR REPLACE text unescaped. A sync partner could
therefore run one attacker-chosen statement per change, for example
an INSERT ... SELECT that copies the sessions table into a synced
option, or a write into a table that is never synced.
updateEntity() now skips a change whose table is not a key of
ENTITY_NAME_TO_ENTITY (or note_reordering), and updateNormalEntity()
skips a row that has a column the receiving table lacks, read from
pragma_table_info. The allow-list is the same map getEntityChangeRow()
uses on the sending side, so no change a genuine peer sends is
refused; the column check rejects exactly the rows SQLite already
rejected with "no such column". A rejected change is logged and
skipped rather than thrown, so one bad record does not roll back the
batch, and it is not recorded in entity_changes, so it never travels
on to other instances.
As a second layer, sql.insert(), replace() and upsert() now throw on
a table, column or primary-key name that is not a plain identifier.
Incoming rows for options that are local-only on this instance are
deliberately still accepted; restricting them changes legitimate sync
behaviour and is out of scope here.
Red before the fix on both the server and standalone runners: an
unknown table and an unknown column threw and aborted the batch, and
SQL smuggled through the entity name or a column key created the
injected option row and an entity change for it.
Assisted-by: Claude Code (Claude Opus 5.5)Editor assessment
This commit patches CVE-2026-135686. Exemplary. The body reconstructs the flaw: updateNormalEntity passed a peer-supplied entity name and the row keys straight into sql.replace, so a sync partner could run one attacker-chosen statement per change, including an INSERT ... SELECT that copied the sessions table into a synced option. It then explains the allow-list, the pragma_table_info column check, why rejecting and logging preserves the batch, and the second-layer identifier guard. The red-before-fix evidence and the explicit out-of-scope note make it fully reviewable.