Skip to content

Commit fe6adb6

Browse files
StanFromIrelandhroncok
authored andcommitted
00492: pythongh-151558: Fix symlink escape via tarfile hardlink-extraction fallback
Security fix for CVE-2026-11940
1 parent 57a647b commit fe6adb6

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

‎Lib/tarfile.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2626,6 +2626,9 @@ def makelink_with_filter(self, tarinfo, targetpath,
26262626
"makelink_with_filter: if filter_function is not None, "
26272627
+ "extraction_root must also not be None")
26282628
try:
2629+
filter_function(
2630+
unfiltered.replace(name=tarinfo.name, deep=False),
2631+
extraction_root)
26292632
filtered = filter_function(unfiltered, extraction_root)
26302633
except _FILTER_ERRORS as cause:
26312634
raise LinkFallbackError(tarinfo, unfiltered.name) from cause

‎Lib/test/test_tarfile.py‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3850,6 +3850,30 @@ def test_sneaky_hardlink_fallback(self):
38503850
self.expect_file("boom", symlink_to='../../link_here')
38513851
self.expect_file("c", symlink_to='b')
38523852

3853+
@support.skip_unless_symlink
3854+
def test_sneaky_hardlink_fallback_deep(self):
3855+
# (CVE-2026-11940)
3856+
with ArchiveMaker() as arc:
3857+
arc.add("a/b/s", symlink_to=os.path.join("..", "escape"))
3858+
arc.add("s", hardlink_to=os.path.join("a", "b", "s"))
3859+
3860+
with self.check_context(arc.open(), 'data'):
3861+
e = self.expect_exception(
3862+
tarfile.LinkFallbackError,
3863+
"link 's' would be extracted as a copy of "
3864+
+ "'a/b/s', which was rejected")
3865+
self.assertIsInstance(e.__cause__,
3866+
tarfile.LinkOutsideDestinationError)
3867+
3868+
for filter in 'tar', 'fully_trusted':
3869+
with self.subTest(filter), self.check_context(arc.open(), filter):
3870+
if not support.can_symlink():
3871+
self.expect_file("a/")
3872+
self.expect_file("a/b/")
3873+
else:
3874+
self.expect_file("a/b/s", symlink_to=os.path.join('..', 'escape'))
3875+
self.expect_file("s", symlink_to=os.path.join('..', 'escape'))
3876+
38533877
def test_exfiltration_via_symlink(self):
38543878
# (CVE-2025-4138)
38553879
# Test changing symlinks that result in a symlink pointing outside

0 commit comments

Comments
 (0)