Skip to content

Commit 54b5dca

Browse files
jaracoclaude
andcommitted
Cover the containment check with a symlink escape test
Co-Authored-By: Claude Opus 5 <[email protected]>
1 parent 6d07b8d commit 54b5dca

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

‎setuptools/tests/test_wheel.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from setuptools._importlib import metadata
2222
from setuptools.wheel import Wheel, _resolve_namespace_dir
2323

24+
from .compat.py39 import os_helper
2425
from .contexts import tempdir
2526
from .textwrap import DALS
2627

@@ -714,6 +715,24 @@ def test_namespace_package_resolves_dotted_name(tmp_path):
714715
assert _resolve_namespace_dir(str(tmp_path), 'ns.pkg') == str(expected)
715716

716717

718+
@pytest.mark.skipif(not os_helper.can_symlink(), reason='Symlink support required')
719+
def test_namespace_package_rejects_symlinked_escape(tmp_path):
720+
"""
721+
A namespace name that is a valid identifier must still not escape through
722+
a symlink that already exists in the egg directory.
723+
"""
724+
dest = tmp_path / 'dest'
725+
dest.mkdir()
726+
outside = tmp_path / 'outside'
727+
outside.mkdir()
728+
(dest / 'ns').symlink_to(outside, target_is_directory=True)
729+
730+
with pytest.raises(ValueError, match='invalid namespace package name'):
731+
_resolve_namespace_dir(str(dest), 'ns')
732+
733+
assert _resolve_namespace_dir(str(dest), 'ok') == str(dest / 'ok')
734+
735+
717736
def test_install_as_egg_rejects_namespace_escape(tmp_path):
718737
"""
719738
An attacker-controlled ``namespace_packages.txt`` must not create files

0 commit comments

Comments
 (0)