Skip to content

Commit 138334f

Browse files
fix: cross-platform absolute path rejection in plugin exporter
Use PurePosixPath + PureWindowsPath to reject absolute paths from both platforms regardless of the current OS. Fixes Windows CI failure where /etc/passwd was not detected as absolute. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 696e1e0 commit 138334f

3 files changed

Lines changed: 10 additions & 4 deletions

File tree

src/apm_cli/bundle/plugin_exporter.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,11 @@
3434

3535
def _validate_output_rel(rel: str) -> bool:
3636
"""Return True when *rel* is safe to write inside the output directory."""
37-
p = Path(rel)
38-
return not p.is_absolute() and ".." not in p.parts
37+
from pathlib import PurePosixPath, PureWindowsPath
38+
39+
if PurePosixPath(rel).is_absolute() or PureWindowsPath(rel).is_absolute():
40+
return False
41+
return ".." not in Path(rel).parts
3942

4043

4144
_SAFE_BUNDLE_NAME_RE = re.compile(r"[^a-zA-Z0-9._-]")

tests/unit/test_plugin_exporter.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,12 @@ def test_rejects_traversal(self):
142142
assert _validate_output_rel("../escape.md") is False
143143
assert _validate_output_rel("agents/../../etc/passwd") is False
144144

145-
def test_rejects_absolute(self):
145+
def test_rejects_absolute_unix(self):
146146
assert _validate_output_rel("/etc/passwd") is False
147147

148+
def test_rejects_absolute_windows(self):
149+
assert _validate_output_rel("C:\\Windows\\System32") is False
150+
148151

149152
class TestRenamePrompt:
150153
def test_strips_prompt_infix(self):

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)