Skip to content

Commit 2ce66d6

Browse files
committed
Bugfix in create_symlink: convert destination, not source to relative paths
1 parent 56617a3 commit 2ce66d6

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

unblob/file_utils.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -568,11 +568,21 @@ def create_symlink(self, src: Path, dst: Path):
568568
"""Create a symlink dst with the link/content/target src."""
569569
logger.debug("creating symlink", file_path=dst, link_target=src, _verbosity=3)
570570

571-
if src.is_absolute():
572-
# convert absolute paths to dst relative paths
573-
# these would point to the same path if self.root would be the real root "/"
574-
# but they are relocatable
575-
src = self._path_to_root(dst.parent) / chop_root(src)
571+
if dst.is_absolute():
572+
# If the symlink destination is absolute, we need to make it relative to the root
573+
# so it can be safely created in the extraction directory.
574+
# If the resulting path points to outside of the extraction directory, we skip it.
575+
dst = self.root / chop_root(dst)
576+
if not is_safe_path(self.root, dst):
577+
self.record_problem(
578+
LinkExtractionProblem(
579+
problem="Potential path traversal through symlink",
580+
resolution="Skipped.",
581+
path=str(dst),
582+
link_path=str(src),
583+
)
584+
)
585+
return
576586

577587
safe_link = self._get_checked_link(src=src, dst=dst)
578588

0 commit comments

Comments
 (0)