Production log (v13.13): "JavaScript heap out of memory" twice, 42 and
74 seconds after the hourly History integrity audit started (its
changeHistory distinct is in the MongoDB log at 03:00:00 and 05:00:00),
both in the first hourly run of a freshly started process. The audit
fetched each board's whole History - every row with its full previous
and new content - and verified the array.
historyVerifier checks one row at a time and keeps only hashes, the first
child of each predecessor, root counts and small summaries; the audit
streams each board through a cursor with a bounded batch, pausing while
the CPU is busy. verifyHistoryRows runs on it and returns exactly what
it did. tests/historyIntegrityStreaming.test.cjs compares both on chains
with forks, a second root, a tampered and an orphan row, and fails if
the audit fetches a board whole.
Thanks to xet7 !
Admin Panel / Problems / Security showed HistoryIntegrity (critical)
81,833 times. A list bound to no one swimlane has swimlaneId '', and the
legacy history append hashed the row with '' and then inserted it
through collection2's default clean, which removes empty strings, after
which the schema's defaultValue stored null: every such list move failed
its own checksum at every audit and was reported as tampering. The
stored-chain path already inserted with { removeEmptyStrings: false,
trimStrings: false }; the legacy path now does too.
Rows already stored that way verify: a null where '' was hashed is
accepted in the id and label fields (boardId, swimlaneId, listId, cardId,
group, batchId, restoredFromId, restoredByUserId) and nowhere else, so a
value replaced by null, a different value, or any change to content, user
or entity still fails.
tests/historyEmptyStringChecksum.test.cjs appends through a collection
that cleans like collection2, verifies already-cleaned rows, fails every
real change, and fails on any ChangeHistory insert in the tree that would
clean or trim; it fails on the code before this commit.
Thanks to Raymond-Voogt and xet7 !
Fixes#6797,
Admin Panel / Problems / Security reported HistoryIntegrity checksum-mismatch,
severity critical, 89472 times, on a board's history row nobody had touched.
Meteor connects to MongoDB/FerretDB with ignoreUndefined, so a content
property that is undefined is dropped when the row is stored. Writers record
such content routinely, for example `deletedAt: list.deletedAt` for a list
that was never deleted. The row's hash covered `"deletedAt":{"$undefined":true}`,
the stored row has no deletedAt, and every background audit found the row
failing its own checksum and reported it again.
- hashHistoryRow() hashes previousContent and newContent as stored: undefined
properties dropped, undefined array elements as null, as the driver does.
New rows verify as the database returns them.
- Rows written before this were hashed with the undefined keys. If the normal
check fails, the keys present in the other side of the change and absent
here are re-added as undefined, which reproduces exactly what was hashed;
nothing else is accepted.
tests/changeHistoryIntegrity.test.cjs stores rows through BSON with
ignoreUndefined, exactly as the driver does: a new row and a pre-fix row both
verify, and a changed value, a removed real value, a change on the other side
and an added key are still caught. The test fails without the fix.
A row that still reports checksum-mismatch after this release changed in a
way an unset value cannot explain, and is worth looking at.
Thanks to xet7 !
Admin Panel -> Problems showed HistoryIntegrity, critical, "history-fork",
89,062 times. Each History row names the row before it, and the legacy
append (every board not migrated to the coordinated chain) read "the
newest row" and inserted after it as two separate steps: two changes
saved at the same moment on one board - two members, or one action whose
hooks record twice at once - both named the same row. Nothing was
tampered with, but the audit called it tampering, and undo, redo and
restore were refused for both rows. The writer gate around the legacy
append counts its writers for a migration; it does not make them take
turns.
- models/lib/historyLegacyAppend.js: a board's appends take turns in
this server, and each links after the chain's tip - the newest row,
then its successors, as Sync History already did - so a createdAt tie
does not fork either. The ordinary recorder, the Scrum restore writer
and Sync's legacy append all use it. Several servers writing one board
at the same moment can still race; the coordinated chain is the answer
to that.
- The hourly audit reported every broken row again every hour, which is
where 89,062 came from; each finding is now reported once
(historyIntegrityReported). It reads the History board by board instead
of all at once, and a fork of two intact rows saved within a minute of
each other is reported as what it is - integrity.historyConcurrentFork,
medium, "a History writer race, not tampering" - while anything else
stays critical.
Existing forks stay as they are (a row's hash cannot be changed), and
undo of their two rows is still refused.
tests/historyLegacyAppend.test.cjs: the old append forks under
concurrency (negative control), twenty appends at once on two boards
make two straight chains, a createdAt tie follows the chain, a failed
append does not stop the next, the audit tells a race from a changed or
late row, and no append in models/ or server/ links by "newest" without
taking turns.
Thanks to xet7 !