Skip to content

Commit 25563af

Browse files
committed
test: reject symlink escape in metadata path-within-root
1 parent 801a1ec commit 25563af

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

‎tests/test_local_metadata.py‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,26 @@ def test_is_within_root_accepts_symlink_alias_forms(self) -> None:
192192
self.assertFalse(helper(outside, real_root))
193193
self.assertFalse(helper(outside, alias_root))
194194

195+
def test_is_within_root_rejects_symlink_escape(self) -> None:
196+
"""In-root symlink to a path outside root must not count as contained."""
197+
helpers = (
198+
local_metadata_is_within_root,
199+
profile_loader_is_within_root,
200+
register_schema_loader_is_within_root,
201+
)
202+
with tempfile.TemporaryDirectory() as temp_dir:
203+
base = Path(temp_dir).resolve()
204+
root = base / "root"
205+
root.mkdir()
206+
secret = base / "secret"
207+
secret.write_text("{}", encoding="utf-8")
208+
link_out = root / "link_out"
209+
link_out.symlink_to(Path("..") / "secret")
210+
211+
for helper in helpers:
212+
with self.subTest(helper=helper.__module__):
213+
self.assertFalse(helper(link_out, root))
214+
195215
def test_detects_when_one_draft_name_overrides_builtin_metadata(self) -> None:
196216
self.assertTrue(draft_activates_automatically("smg_modbus.json", None))
197217
self.assertTrue(draft_activates_automatically("smg_modbus.json", "smg_modbus.json"))

0 commit comments

Comments
 (0)