fix(checkpoint): keep snapshots inside the checkpoint directory - #1173
Open
rascal-sl wants to merge 1 commit into
Open
fix(checkpoint): keep snapshots inside the checkpoint directory#1173rascal-sl wants to merge 1 commit into
rascal-sl wants to merge 1 commit into
Conversation
rascal-sl
requested review from
Avtrkrb,
akramcodez and
will-lamerton
as code owners
September 4, 2026 06:08
Contributor
Author
|
The red check is Package Audit, and it is a registry timeout rather than an advisory: This branch changes two source files and adds a changeset, no dependency or lockfile changes, so there is nothing here for |
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.
Closes #1148.
The problem
A snapshot is keyed by its path relative to the workspace:
captureFilesdoes not require the file to be inside the workspace, so a file above it comes back as../name.saveCheckpointthen joined that straight onto the checkpoint's files directory:which writes outside
files/.restoreCheckpointhad the same join when reading snapshots back, driven bymetadata.filesChangedoff disk.Worth noting
file-snapshot.tsalready refuses to restore or delete a path outside the workspace. The gap was only on the checkpoint copy.The fix
getCheckpointDiralready contains this exact containment rule for checkpoint names, so this reuses it asisSafeSnapshotPath, expressed on the relative path so it can run before a base directory exists.path.normalizefirst, soa/../../bis caught as well as a leading.., and absolute paths are rejected.It runs at two points, which are two different trust boundaries:
filesChangedand the files actually written cannot disagree.metadata.jsonis on-disk state that may have been written by a version without the first check, or edited by hand.An unsafe path is skipped with a warning rather than aborting the checkpoint, matching how
file-snapshot.tsalready handles the same situation.Test plan
Two tests added to
checkpoint-manager.spec.ts.Confirmed the first fails without the source change:
That
trueisexistsSyncfinding the snapshot written outsidefiles/. With the fix,npx ava source/services/checkpoint-manager.spec.tspasses 28 tests. The second test covers a normal workspace file so the guard cannot over-block.tsc --noEmitandbiome checkare clean.Three
cli-integrationtests fail in the full suite. They fail identically onupstream/mainwith this branch's changes stashed, so they are pre-existing and unrelated.