Commit Graph

46 Commits

Author SHA1 Message Date
Thomas Waldmann 35ac39b751
fix F401 2023-07-26 01:23:37 +02:00
Thomas Waldmann b97c3d3a55
simplify BaseTestCase.assert_raises 2023-07-25 15:14:46 +02:00
Thomas Waldmann a2e7854911
simplify changedir with @contextmanager 2023-07-25 15:12:32 +02:00
Thomas Waldmann 02fcabe31f
remove unused methods of BaseTestCase
also: clean up imports / comments
2023-07-25 15:07:53 +02:00
Thomas Waldmann b8a52a4769
tests: remove usage of environment_variable context manager
rather use monkeypatch.setenv/delenv.
2023-07-25 13:29:02 +02:00
Peter Gerber 438cf2e7ef
Sanitize paths during archive creation/extraction/...
Paths are not always sanitized when creating an archive and,
more importantly, never when extracting one. The following example
shows how this can be used to attempt to write a file outside the
extraction directory:

$ echo abcdef | borg create -r ~/borg/a --stdin-name x/../../../../../etc/shadow archive-1 -
$ borg list -r ~/borg/a archive-1
-rw-rw---- root   root          7 Sun, 2022-10-23 19:14:27  x/../../../../../etc/shadow
$ mkdir borg/target
$ cd borg/target
$ borg extract -r ~/borg/a archive-1
x/../../../../../etc/shadow: makedirs: [Errno 13] Permission denied: '/home/user/borg/target/x/../../../../../etc'

Note that Borg tries to extract the file to /etc/shadow and the
permission error is a result of the user not having access.

This patch ensures file names are sanitized before archiving.
As for files extracted from the archive, paths are sanitized
by making all paths relative, removing '.' elements, and removing
superfluous slashes (as in '//'). '..' elements, however, are
rejected outright. The reasoning here is that it is easy to start
a path with './' or insert a '//' by accident (e.g. via --stdin-name
or import-tar). '..', however, seem unlikely to be the result
of an accident and could indicate a tampered repository.

With paths being sanitized as they are being read, this "errors"
will be corrected during the `borg transfer` required when upgrading
to Borg 2. Hence, the sanitation, when reading the archive,
can be removed once support for reading v1 repositories is dropped.
V2 repository will not contain non-sanitized paths. Of course,
a check for absolute paths and '..' elements needs to kept in
place to detect tempered archives.

I recommend treating this as a security issue. I see the following
cases where extracting a file outside the extraction path could
constitute a security risk:

a) When extraction is done as a different user than archive
creation. The user that created the archive may be able to
get a file overwritten as a different user.
b) When the archive is created on one host and extracted on
another. The user that created the archive may be able to
get a file overwritten on another host.
c) When an archive is created and extracted after a OS reinstall.
When a host is suspected compromised, it is common to reinstall
(or set up a new machine), extract the backups and then evaluate
their integrity. A user that manipulates the archive before such
a reinstall may be able to get a file overwritten outside the
extraction path and may evade integrity checks.

Notably absent is the creation and extraction on the same host as
the same user. In such case, an adversary must be assumed to be able
to replace any file directly.

This also (partially) fixes #7099.
2023-06-07 23:23:53 +02:00
Thomas Waldmann 2692fa1146
skip "do not retry when permissions denied" test if running as root
we can not take away read permissions for root,
so the test would fail.
2023-03-28 15:55:10 +02:00
Michael Deyaso 2c232449b0
Modified Item.pyx to include diffs in ctime and mtime (#7335)
diff: include changes in ctime and mtime, fixes #7248

also:
- sort JSON output alphabetically
- add --content-only to ignore metadata changes

Co-authored-by: Michael Deyaso <mdeyaso@fusioniq.io>
2023-03-06 23:18:36 +01:00
Thomas Waldmann 2ef09eaa77
same_ts_ns: add a timestamp comparison function
also: HAVE_UTIMES means 1us resolution (*)

(*) at least as far as the utimes() call is concerned.

Whether there are other limitations has to be seen.
2023-02-11 01:19:01 +01:00
Thomas Waldmann b8e48c5036 mypy: fixes / annotations 2022-07-15 14:54:48 +02:00
Thomas Waldmann 7957af562d blacken all the code
https://black.readthedocs.io/
2022-07-06 16:34:38 +02:00
Thomas Waldmann 350393c9fd remove unused imports 2022-07-05 00:05:07 +02:00
Thomas Waldmann 1c707b7da2 cli: use --repo option instead of positional repo parameter
currently still with ::archive appended.
2022-06-15 16:36:56 +02:00
Thomas Waldmann cbeef56454 pyupgrade --py38-plus ./**/*.py 2022-02-27 20:11:56 +01:00
Andrey Bienkowski 37506ca8af Refactor: remove assert_true (master)
Work toward https://github.com/borgbackup/borg/issues/28
2022-01-22 23:49:34 +03:00
Andrea Gelmini 72e7c46fa7 Fix typos 2021-01-07 17:54:33 +01:00
Thomas Waldmann 49b1421682 FUSE: support pyfuse3 additionally to llfuse, fixes #5407
FUSE implementation can be switched via env var BORG_FUSE_IMPL.
2020-10-31 22:04:44 +01:00
Thomas Portmann ef9fdcf992 fix race condition in lock migration, fixes #4953
- add a daemonizing() ctx manager

The foreground borg mount process (local repo) survives until the lock
migration (performed by the background) is finished, so the lock to be
migrated is never stale, and the race condition is gone.

- add a test case revealing that locking is not safe during daemonization (borg mount)

- amend printing in testsuite.archiver
2020-07-09 21:31:13 +02:00
finefoot 07e445f026
Fix read-only tests for fakeroot environment 2020-04-20 20:29:37 +02:00
finefoot f320384827
Fix testing of unsuccessful mount 2020-04-19 22:24:11 +02:00
TW 81e70711e2
Merge pull request #4862 from jrast/win-repo-path
Accept absolute paths on windows
2020-04-16 20:24:46 +02:00
finefoot 842cfc8cdb
Fix tests of read-only repos for non-root users 2020-04-13 18:41:41 +02:00
TW c867ebfeb6
Merge pull request #5048 from finefoot/patch-8
Option to bypass locking to use sensible borg commands with read-only repositories
2020-04-11 22:18:37 +02:00
finefoot e49a17143d Add option to bypass locking mechanism 2020-04-11 17:04:52 +02:00
Jürg Rast 8e855ecb8a Accept absolute paths on windows
Accept absolute repo paths on windows.
2020-04-11 17:01:29 +02:00
Thalian 08a7661e67 [FEATURE] #4489 – Deprecate --nobsdflags option
Replaced by --noflags. In internal data structure the key 'bsdflags' is kept for backwards compatibility.
2020-03-25 06:35:15 +01:00
TW 597b09a993 support platforms with no os.link (#4903)
support platforms with no os.link, fixes #4901

if we don't have os.link, we just extract another copy instead of making a hardlink.

for that to work, we need to have (and keep) the chunks list in hardlink_masters.
2020-03-03 23:34:54 -05:00
Thomas Waldmann c0a617c6a9 cope with ANY error when importing pytest into borg.testsuite, #4652
this happened because the user had pytest5 installed somehow,
although it is incompatible with python 3.4:

# python3 /usr/local/bin/borg --version
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/borg/archiver.py", line 81, in <module>
    from .selftest import selftest
  File "/usr/local/lib/python3.4/dist-packages/borg/selftest.py", line 21, in <module>
    from .testsuite.hashindex import HashIndexDataTestCase, HashIndexRefcountingTestCase, HashIndexTestCase
  File "/usr/local/lib/python3.4/dist-packages/borg/testsuite/__init__.py", line 29, in <module>
    from pytest import raises
  File "/usr/local/lib/python3.4/dist-packages/pytest.py", line 6, in <module>
    from _pytest.assertion import register_assert_rewrite
  File "/usr/local/lib/python3.4/dist-packages/_pytest/assertion/__init__.py", line 6, in <module>
    from _pytest.assertion import rewrite
  File "/usr/local/lib/python3.4/dist-packages/_pytest/assertion/rewrite.py", line 443, in <module>
    ast.MatMult: "@",
AttributeError: 'module' object has no attribute 'MatMult'
2019-07-02 23:12:43 +02:00
Emmo Emminghaus 973921df5a remove unneded code and remarks, added needed except clause 2018-11-10 21:56:39 +01:00
Emmo Emminghaus 558ca61d20 remove posix issues and fixup for unsupported methodes 2018-11-10 21:48:46 +01:00
Thomas Waldmann 10cdadb2f8 flake8: fix F841 2018-10-29 12:36:03 +01:00
Thomas Waldmann 9deb90db71 xattr: use bytes typed names for listxattr, getxattr, setxattr 2018-07-07 15:47:56 +02:00
Sam H b0141c1dc9 include item birthtime in archive (where available) (#3313)
include item birthtime in archive, fixes #3272

* use `safe_ns` when reading birthtime into attributes
* proper order for `birthtime` in `ITEM_KEYS` list
* use `bigint` wrapper for consistency
* Add tests to verify that birthtime is normally preserved, but not preserved when `--nobirthtime` is passed to `borg create`.
2017-11-13 14:55:10 +01:00
Marian Beermann 2fe37dba7f umount: try fusermount, then try umount 2017-07-24 13:55:32 +02:00
Thomas Waldmann 7ebad4f803 FUSE vs. fuse 2017-06-24 01:24:14 +02:00
Thomas Waldmann 6f81d24324 remove unused no_lchflags_because 2017-05-22 17:54:43 +02:00
Thomas Waldmann efec00b39c use stat with follow_symlinks=False
should be equivalent to using os.lstat() before.
2017-05-22 17:54:42 +02:00
enkore 5788219ff4 borg export-tar (#2519) 2017-05-17 00:09:41 +02:00
Thomas Waldmann afab1cc9b0 Merge branch '1.0-maint'
# Conflicts:
#	borg/platform.py
#	src/borg/archiver.py
#	src/borg/helpers.py
#	src/borg/platform/darwin.pyx
#	src/borg/platform/freebsd.pyx
#	src/borg/platform/linux.pyx
#	src/borg/testsuite/__init__.py
2016-11-17 23:56:34 +01:00
Thomas Waldmann 8a15916284 Merge branch '1.0-maint' into merge-1.0-maint
# Conflicts:
#	docs/changes.rst
#	docs/usage/help.rst.inc
#	src/borg/cache.py
#	src/borg/remote.py
#	src/borg/testsuite/__init__.py
#	src/borg/testsuite/archiver.py
2016-10-31 18:24:13 +01:00
Thomas Waldmann 09e74af7bf Merge branch '1.0-maint' 2016-10-24 21:41:20 +02:00
Thomas Waldmann b0cc4fd74a Merge branch '1.0-maint' into merge-1.0-maint 2016-10-13 19:10:04 +02:00
Lee Bousfield b86b5d952a
Filesystem feature detection and test skipping 2016-07-31 01:19:31 -04:00
Thomas Waldmann 3baa8a3728 Merge branch '1.0-maint'
# Conflicts:
#	docs/changes.rst
#	docs/usage/mount.rst.inc
#	src/borg/archive.py
#	src/borg/archiver.py
#	src/borg/fuse.py
#	src/borg/testsuite/archiver.py
2016-07-11 01:23:27 +02:00
Thomas Waldmann 3ce35f6843 Merge branch 'master' into move-to-src 2016-05-21 19:06:01 +02:00
Thomas Waldmann d1ea925a5b move borg package to src/ 2016-05-05 20:19:50 +02:00
Renamed from borg/testsuite/__init__.py (Browse further)