Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/path_scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ def validate_payload(self, payload: str, cwd: str | Path | None = None) -> PathS
def validate_path(self, candidate: str | Path, cwd: str | Path | None = None) -> PathScopeDecision:
raw = os.path.expandvars(os.path.expanduser(str(candidate)))
if _is_windows_absolute(raw):
return self._validate_windows_path(raw)
if os.name != 'nt':
return self._validate_windows_path(raw)
elif not any(_is_windows_absolute(str(root)) for root in self.roots):
# Even on Windows, deny if no roots are Windows absolute paths (edge case)
return PathScopeDecision(False, 'windows absolute path is outside workspace scope', str(candidate), raw)

base = Path(cwd).expanduser().resolve(strict=False) if cwd else self.roots[0]
path = Path(raw)
if not path.is_absolute():
Expand Down Expand Up @@ -116,7 +121,7 @@ def extract_path_candidates(payload: str) -> tuple[str, ...]:
tokens = payload.split()
raw_tokens = payload.split()
candidates: list[str] = []
for token in (*tokens, *raw_tokens):
for token in (*raw_tokens, *tokens):
if not token or token.startswith('-') or _ENV_ASSIGNMENT_RE.match(token):
continue
token = _strip_redirection_operator(token)
Expand Down
13 changes: 11 additions & 2 deletions tests/test_security_scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ def test_explicit_worktree_roots_are_allowed(self) -> None:

self.assertTrue(decision.allowed, decision.reason)

def test_extract_path_candidates_preserves_unc_paths(self) -> None:
payload = r'type \\server\share\secret.txt'
candidates = extract_path_candidates(payload)
self.assertIn(r'\\server\share\secret.txt', candidates)

def test_windows_absolute_paths_are_denied_for_posix_workspace(self) -> None:
with tempfile.TemporaryDirectory() as tmp:
workspace = Path(tmp) / 'workspace'
Expand All @@ -116,9 +121,13 @@ def test_windows_absolute_paths_are_denied_for_posix_workspace(self) -> None:
unc_decision = WorkspacePathScope.from_root(workspace).validate_payload(r'type \\server\share\secret.txt')

self.assertFalse(drive_decision.allowed)
self.assertIn('windows absolute path', drive_decision.reason)
self.assertFalse(unc_decision.allowed)
self.assertIn('windows absolute path', unc_decision.reason)
if os.name == 'nt':
self.assertIn('outside workspace scope', drive_decision.reason)
self.assertIn('outside workspace scope', unc_decision.reason)
else:
self.assertIn('windows absolute path', drive_decision.reason)
self.assertIn('windows absolute path', unc_decision.reason)

def test_file_and_shell_tools_use_workspace_scope_context(self) -> None:
with tempfile.TemporaryDirectory() as tmp:
Expand Down