Skip to content

security: same local repo dir via another path is not a relocation, fixes #8188 - #10578

Open
ThomasWaldmann wants to merge 1 commit into
borgbackup:1.4-maintfrom
ThomasWaldmann:same-repo-dir-8188-14
Open

ThomasWaldmann wants to merge 1 commit into
borgbackup:1.4-maintfrom
ThomasWaldmann:same-repo-dir-8188-14

Conversation

@ThomasWaldmann

Copy link
Copy Markdown
Member

Backport of #10516 to 1.4-maint. Fixes #8188.

The "repository was previously located at" check in SecurityManager.assert_location_matches() (in cache.py on 1.4) compared path strings only. So reaching the same local repository directory via a different path looked like a relocation:

  • a symlink (bar -> foo)
  • a bind mount
  • a different letter case on a case-insensitive filesystem (e.g. FOO vs foo on macOS APFS)

Answering "yes" rewrote the stored location, so alternating between the paths kept re-triggering the prompt, which breaks unattended runs (e.g. prune).

Change

If the path strings differ, borg now also checks whether both are local paths referring to the same existing directory (os.stat + os.path.samestat). If they do, there is no warning.

  • The stored location and all displayed paths are unchanged.
  • It only applies to local (file) repositories with an absolute previous path. ssh:// locations are never affected.
  • If the old path no longer exists (a real move/rename), the warning appears as before.
  • Filesystems reporting st_ino == 0 are never treated as "same".

Differences from the master PR: the code lives in cache.py, and the tests are in the unittest-style ArchiverTestCase in testsuite/archiver.py (skipped for the remote variant). The NFC/NFD normalization from #2913 is not on 1.4-maint, so this change does not include it.

Tests

  • New test_repository_access_via_symlink: repo path, then symlink, then repo path again, with BORG_RELOCATED_REPO_ACCESS_IS_OK=no. It expects no abort and an unchanged stored location. It fails without the fix.
  • New test_repository_previously_remote: a previously stored ssh:// location still triggers the abort.
  • The existing test_repository_move still covers a real rename.

The FAQ entry "How do I rename a repository?" got one sentence about this.

🤖 Generated with Claude Code

…ixes borgbackup#8188

The "repository was previously located at" check compared path strings only,
so reaching the same local repository directory via a symlink, a bind mount or
a different letter case on a case-insensitive filesystem looked like a
relocation. Answering yes rewrote the stored location, so alternating between
the paths kept triggering the prompt (breaking e.g. unattended prune).

If the strings differ, but both are local paths referring to the same existing
directory (same st_dev/st_ino, st_ino != 0), do not warn. The stored location
and all displayed paths stay as they were. Remote locations are not affected,
and a real move/rename (old path gone) still triggers the warning.

Backport of borgbackup#10516.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.13%. Comparing base (e81a51f) to head (782b197).
⚠️ Report is 12 commits behind head on 1.4-maint.

Additional details and impacted files
@@              Coverage Diff              @@
##           1.4-maint   #10578      +/-   ##
=============================================
+ Coverage      82.11%   82.13%   +0.01%     
=============================================
  Files             38       38              
  Lines          11485    11496      +11     
  Branches        1810     1812       +2     
=============================================
+ Hits            9431     9442      +11     
  Misses          1468     1468              
  Partials         586      586              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

This branch has not been deployed

No deployments
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