Skip to content

fix: sync pull keeps every write inside the destination - #114

Merged
bchatelard merged 1 commit into
mainfrom
sync-pull-stay-in-destination
Nov 6, 2026
Merged

bchatelard merged 1 commit into
mainfrom
sync-pull-stay-in-destination

Conversation

@bchatelard

Copy link
Copy Markdown
Member

Why

filesystem.sync(direction="pull") writes local paths that come from the sandbox: the listing (GET /files/list)
and the archive (GET /files/archive). Until now only archive member names were checked (no leading /, no ..).
Listing paths were joined as given, and writes went through whatever sat on the path: a symlink extracted earlier in
the same pull, or one already in the destination. A pull should never write outside its destination, whatever the
sandbox's tree holds.

What changed

All pull writes now go through join_local, which:

  • runs the archive member check on every path (absolute and .. paths refused), plus a containment check that also
    covers Windows separators and drives;
  • refuses a path whose parents under the destination include a symlink.

On top of that:

  • every listing path is checked before anything is fetched;
  • extracted files and download_file's .part file are opened with O_NOFOLLOW (where the platform has it);
  • directory modes and mtimes, applied after the contents, skip a path that is no longer a directory.

Symlinks themselves are still kept as sent, like rsync -l: sync just never writes through them.

Behavior changes:

  • A pull whose listing or archive holds such a path now fails with SandboxFilesystemError instead of writing it.
  • A pull with delete=True where a directory became a symlink no longer deletes the directory's old children
    through the new link (they were removed from the link's target). The delete still counts.
  • download_file refuses a symlink at <local_path>.part instead of writing through it.

docs/sandbox.md is regenerated for the new docstrings (clean_path, open_nofollow, join_local, sync).

How it was verified

  • uv run pytest: 1857 passed.
  • 10 new tests (archive members through a symlink member or an existing symlink, directory mode through a later
    symlink, listing paths outside the destination, oversized downloads through a symlink, a .part symlink, a
    dir → symlink flip with delete=True, join_local refusals; sync and async pulls) fail on main and pass here.
  • black --check on the changed files.

A pull takes its paths from the sandbox's listing and archive. They now go
through the same check before any local write:

- listing paths get the archive member check (no absolute or .. paths),
  before anything is fetched;
- join_local refuses a path whose parents under the destination include a
  symlink, for archive members, oversized downloads and deletes alike;
- extracted files and the download's .part file are opened with
  O_NOFOLLOW;
- directory modes and mtimes, applied last, skip a path that is no longer
  a directory.

Symlinks themselves are still kept as sent, like rsync -l; sync just never
writes through them. This also fixes a pull with delete=True where a
directory became a symlink: its old children were deleted through the new
link, in the link's target.
@bchatelard
bchatelard marked this pull request as ready for review November 6, 2026 15:24
@bchatelard
bchatelard merged commit 4a835a4 into main Nov 6, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant