Repository navigation
Conversation
Owner
Author
|
Security: CHANGES at b062bb9
|
… reports (#1188) The writer collected plaintext and encrypted copies into one list and pruned the merged list to a single BACKUP_KEEP of 14, while the dry run, loadConfig and the /admin card report BACKUP_KEEP_PLAINTEXT (1) and BACKUP_KEEP_ENCRYPTED (30). With the shipped defaults that deletes seven of twenty encrypted copies the card says are kept, silently, and leaves fourteen plaintext copies while the card shows thirteen expired — a deletion the next run will not take. The writer now prunes each class at its own count, with the defaults imported from scripts/lib/backup-manifest.mjs so there is one definition rather than a second constant. --keep / BACKUP_KEEP stays an explicit override of both classes for one run and the retention= line prints the counts it applied.
…1188) The kept set was chosen by mtime alone, so a plaintext copy with a future mtime (a clock stepped back, or a set restored with `cp -a`) outranked the copy the run had just written: the writer pruned its own backup, printed a `backup=` path for a file that no longer existed, and still said `backup: OK`. `prune` now pins the run's target first inside its class before slicing, so the written copy is kept even when it is not the newest by mtime, and the run refuses after pruning if that path is gone instead of reporting success for a file no reader can open. `--keep` / `BACKUP_KEEP` is validated whenever it was supplied: an explicitly empty value is refused with exit 2 instead of falling through to the defaults, and an accepted override still prints `override=--keep`.
Owner
Author
|
Security: PASS at 539ea74 Replaces: b062bb9
|
HugoXK-bot
approved these changes
Nov 20, 2026
HugoXK-bot
left a comment
Collaborator
There was a problem hiding this comment.
Verdict: PASS at 539ea74
I read the live PR myself: head 539ea744 (tree 72ac6e60, parent b062bb94), body raw 98ee299c1b2d (12,876 B), and no review object on the PR. The earlier 8a0095af body is not live.
- Blocker 1, read and reproduced:
prune(dir, keep, target)moves the entry whose path equalstargetto the front of its own class beforesorted.slice(keep[kind])(scripts/backup.mjs:101-105), and the run refuses after pruning when that path is gone (:229,backup: the backup this run wrote is missing after pruning). With this tip's test file on theb062bb94writer,a copy with a future mtime never outranks the copy the run writesfails (12 tests / 10 pass / 2 fail: the run reports abackup=path it already deleted); at the tip that node passes and the future-dated copy is the one removed. - Blocker 2, read and reproduced: supplied is separated from non-empty (
Object.hasOwn(args, 'keep') || process.env.BACKUP_KEEP !== undefined,:125-127) and validated bykeepCount(:55-63) before anything is created. At the tip--keep "",BACKUP_KEEP=""and a bare--keepall exit 2 with--keep must be a positive whole number, got an empty value/got no value; atb062bb94the same node fails 0 !== 2 with the directory untouched afterwards.BACKUP_KEEP=2is accepted and printsretention=keep:plaintext=2,encrypted=2 override=--keep. - The counts are the console's counts:
DEFAULT_KEEP_PLAINTEXT1 /DEFAULT_KEEP_ENCRYPTED30 are imported fromscripts/lib/backup-manifest.mjs:98-99, the same constantssrc/config.ts:677-679and the dry run read; the per-class variables keep the documented empty-means-default reading (src/config.ts:304-309), and only the one-run--keep/BACKUP_KEEPoverride refuses an empty value. Theretention=keep:plaintext=N,encrypted=N[ override=--keep]line is what the tests assert. - Red/green reproduced myself:
f1c48ed3with the original nine-node file → 9 tests / 8 pass / 1 fail;b062bb94with the twelve-node file → 12 / 10 / 2; tip → 12 / 12 / 0; the five backup suites at the tip → 57 passed, 0 failed.ci-ok136467507790is green at the head, every other check is success, and thereview-gatered is the pre-PASS state. T3 basisscripts/backup.mjs(4 files, +248/−29, inside the advisory limits); 无 UI 面 — CLI only. The docs and changelog changes state the per-class counts, the override of both, the empty-value refusal and the written-copy guarantee, so nothing is left unnamed.
Ran:
npx tsx --test test/backupPrune.test.tsat539ea744— 12 pass / 0 failnpx tsx --test test/backupPrune.test.ts test/backup.test.ts test/backupPlaintext.test.ts test/backupEncryption.test.ts test/adminBackup.test.tsat539ea744— 57 pass / 0 failnpx tsx --test test/backupPrune.test.tswith this test file onb062bb94— 12 tests, 10 pass, 2 failnpx tsx --test test/backupPrune.test.tswith the original nine-node file onf1c48ed3— 9 tests, 8 pass, 1 failnode scripts/backup.mjs ... --keep/--keep ""/BACKUP_KEEP=""/BACKUP_KEEP=2at539ea744— exit 2 for the three empty shapes, exit 0 with the override marker for2
Not run:
npm run checkat the tip (CItest (24),coverage,typecheck,lint,buildare green; I ran the five backup suites)- a real host backup or any production retention change — every directory was temporary
- the keyed encryption path beyond
test/backupEncryption.test.ts
Replaces: b062bb9
Written-by: HugoXK-bot
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Written-by: Fledge Platform Dev-2
Fixes #1188
What changed
scripts/backup.mjs— the only program that deletes a backup — prunes each class at its own write-time count, keeps the copy the run just wrote, and validates an override that was actually supplied:copyKind()fromscripts/lib/backup-manifest.mjsinstead of a mergedfledge-*.db+fledge-*.db.enclist, sorts each class by mtime and slices it at that class's count, deleting the copy's manifest with it;BACKUP_KEEP_PLAINTEXT/BACKUP_KEEP_ENCRYPTED, with the defaults imported fromscripts/lib/backup-manifest.mjs(DEFAULT_KEEP_PLAINTEXT1,DEFAULT_KEEP_ENCRYPTED30) rather than redefined, so the writer, the dry run andloadConfigcannot drift apart;scripts/backup-prune.mjsandsrc/config.ts— a positive whole number,0refused rather than clamped;--keep/BACKUP_KEEPremains an explicit override of both classes for one run, and the run says so:retention=keep:plaintext=N,encrypted=N override=--keep. Without the override the line prints both counts it applied, e.g.retention=keep:plaintext=1,encrypted=30. The override applies to both classes; an empty value is refused, never treated as absent;prune()now takes the path this run wrote and moves it to the front of its class before slicing, so the written copy is never the pruned one — not even when a stale copy carries a future mtime;--keep "",BACKUP_KEEP=""and a bare--keepexit 2 through the same refusal the invalid-count path uses, before anything is written or deleted.docs/deploy.mdis rewritten in the same PR at the two blocks the card names: thenpm run db:backupcomment and the retention section. The comment now says an empty--keep/BACKUP_KEEPis refused, and the retention paragraph says an explicitly supplied but empty value is refused with exit 2 and that the copy a run writes is always among the copies its class keeps, even when an older copy carries a future mtime.changelog.d/1188.fixed.mdnames both.Red first, per assertion, at the base
f1c48ed3513a8180b870fae19fb95d32222da44b, with the original nine-node test file dropped onto an otherwise untouched checkout (# tests 9 / # pass 8 / # fail 1). The split is the card's, not a summary of it:retention=keep:14 pruned=7), not the 20 the plan says are kept. TheexpiredCopies === 0leg is green at the base by construction (13 is under the displayedkeepEncrypted30, so the displayed policy reports nothing expired) — it is the post-fix agreement guard, not part of the red.retention=keep:14 pruned=7) instead of 1, and the plan afterwards reports 13 expired instead of 0.retention=line assertion is also red at the base, because the base printskeep:14.Security review at b062bb9 — both blockers
Security comment
7046476556named two data-loss paths inscripts/backup.mjs. Both are answered in this tip, and each has its own node intest/backupPrune.test.ts.Blocker 1 — the run's own copy is not pinned into the kept set
At
b062bb9the kept set is chosen by mtime alone (:93-97slice,:209-210report). Reproduced in the new fixture: one plaintext copy with an mtime one hour in the future (utimesSync) is joined by the copy the run writes; sorted by mtime the future-dated stale copy is first, the writer prunes the copy it just wrote, exits 0, and printsbackup=<path>for a file that no longer exists, thenbackup: OK. Atf1c48ed3both copies survived.Answer.
prune(dir, keep, target)now finds the entry whose path equals the run'stargetand moves it to the front of its class beforesorted.slice(keep[kind])(scripts/backup.mjs:101-106). The class is still kept at exactly its configured count — pinning reorders, it does not enlarge the set — and the written copy is inside the kept prefix by path, not by mtime. As a truth guard, after pruning the run checks the path still exists and exits 1 withbackup: the backup this run wrote is missing after pruning: <path>(:225-229) instead of printingbackup=/backup: OKfor a file no reader can open.New node:
a copy with a future mtime never outranks the copy the run writes. It asserts thebackup=path exists on disk, the future-dated copy is the one gone,pruned=1, and the plan afterwards is empty.Blocker 2 — an explicitly passed but empty override is treated as absent
At
b062bb9an empty value is read as "no override" (:56returns the fallback,:110-111maps''tonull), so--keep ""andBACKUP_KEEP=""prune at the defaults with exit 0; a wrapper whose variable expands empty deletes with exit 0 wheref1c48ed3refused with exit 2. Theoverride=--keepmarker disappears with the value, so the line cannot show that an override was consumed.Answer. "Supplied" is now separate from "non-empty":
Object.hasOwn(args, 'keep') || process.env.BACKUP_KEEP !== undefined(scripts/backup.mjs:125-127). A supplied value goes throughkeepCount, which refuses an empty or missing one with the invalid-count sentence and exit 2 —--keep must be a positive whole number, got an empty valueorgot no value(:55-63) — before any path is written or deleted. An accepted override still printsoverride=--keep, because the marker is printed for every supplied and accepted override.New node:
an explicitly empty keep override is refused, not treated as absent. It runs both shapes,--keep ""andBACKUP_KEEP="", against three planted plaintext copies and asserts exit 2, the refusal on stderr, nobackup=line, and a byte-identical directory listing afterwards. A third node,an accepted keep override still prints the override marker, proves the marker path still printsretention=keep:plaintext=2,encrypted=2 override=--keep pruned=2.Red at b062bb9 for the two new nodes
With the three new nodes in place and
scripts/backup.mjsleft atb062bb9:a copy with a future mtime never outranks the copy the run writes—the run reported a backup it had already pruned: …/fledge-2026-11-20T18-14-53-984Z.db, andexistsSyncon the printed path was false: the written copy was the pruned one.an explicitly empty keep override is refused, not treated as absent—Expected values to be strictly equal: 0 !== 2: both empty shapes pruned at the defaults and exited 0.an accepted keep override still prints the override markeris green atb062bb9and stays green; it is the no-regression node for the marker.At the tip
539ea744f367fbc232ca80e1843cd846fc339083, tree72ac6e6083e09693c7a4e9ba21df5ba954753da1:npm run checkat the tip: lint11 warning(s) in 8 entries match the baseline, typecheck clean,# tests 3268 / # pass 3267 / # fail 0(1 skipped:the change that decides how a release PR merges may not also edit the gate that judges it), build clean.node scripts/version.mjs check→version: 0.4.4 ok;node scripts/changelog.mjs check→changelog: 23 fragment(s) ok.The two runs at the shipped defaults, on the card's own fixture:
expiredCopies 0;expiredCopies 0;--keep 2over five encrypted copies leaves two and printsretention=keep:plaintext=2,encrypted=2 override=--keep pruned=3;--keep lotsexits 2 with--keep must be a positive whole number, got lots;--keep ""exits 2 with--keep must be a positive whole number, got an empty value.Risk tier
node scripts/risk-gate.mjs --base origin/mainat the shipping tree, verbatim:T3, unchanged from the first tip: this needs a PASS at this tip plus green
ci-ok. Four files, +248/−29 againstf1c48ed3.Alternatives considered
--keepentirely. Rejected in the card: a host wrapper that passes--keepwould stop writing backups at the next cron, turning a retention mismatch into a backup outage.--keep-plaintext/--keep-encryptedflags to the writer. Rejected: the environment variables are already the interfaceloadConfigand the dry run use, and a third shape would need its own documentation for no new capability.Uncertainty and residual risk
The writer still collects stale
.plaintext.tmpintermediates and leaves-wal/-shmsidecars alone, exactly as before. The per-classBACKUP_KEEP_PLAINTEXT/BACKUP_KEEP_ENCRYPTEDvariables keep their documented empty-means-default reading, which is the readingloadConfigand the dry run apply; only the one-run--keep/BACKUP_KEEPoverride refuses an empty value, because only that value is passed as a deletion instruction for this run. The first real deletion of an existing host's backlog still happens on the next scheduled run; an operator who wants to see it first should diffbackup-prune.mjs --jsonagainst the run'sretention=line.Rollback
Revert the commit. The writer returns to per-class counts without the pin and without the empty-value refusal; no schema, no state written outside the backup directory.
UI surface
None —
scripts/backup.mjsis a CLI; no page, asset or string changes.Docs and changelog
docs/deploy.mdis updated in this PR (the backup command block and the retention section).changelog.d/1188.fixed.mdcarries the user-visible line. NoDocs-not-needed:claim.Ran:
npx tsx --test test/backupPrune.test.tsatf1c48ed3513a8180b870fae19fb95d32222da44bwith the original nine-node file —# tests 9 / # pass 8 / # fail 1npx tsx --test test/backupPrune.test.tsatb062bb9406a4b1a032e8fd7162a7be911d523188with the twelve-node file —# tests 12 / # pass 10 / # fail 2npx tsx --test test/backupPrune.test.tsat539ea744f367fbc232ca80e1843cd846fc339083— 12 passed, 0 failednpx tsx --test test/backupPrune.test.ts test/backup.test.ts test/backupPlaintext.test.ts test/backupEncryption.test.ts test/adminBackup.test.tsat the tip — 57 passed, 0 failednpm run checkat the tip — exit 0 (# tests 3268 / # pass 3267 / # fail 0, 1 skipped, lint and typecheck clean, build ok)node scripts/risk-gate.mjs --base origin/mainat the shipping tree —risk-tier: T3; basis: scripts/backup.mjsnode scripts/changelog.mjs checkat the tip — 23 fragments oknode scripts/version.mjs checkat the tip — 0.4.4 okb062bb9and at the tip, withbackup-prune.mjs --jsonread before and afterutimesSyncone hour ahead) atb062bb9and at the tip--keep 2,--keep lots,--keep ""andBACKUP_KEEP=""at the tipNot run:
test/backupEncryption.test.tsalready covers the keyed pathscripts/restore-drill*(out of scope,#463owns it), Docker image build, real SMTPanswering body
bae671b564e2(issue-gate) and Security comment7046476556atb062bb9