Skip to content
Merged
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
2 changes: 1 addition & 1 deletion coding-agent/src/coding_agent/tools/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def _validated_execution_cwd(

def _validate_no_path_escape(args: list[str], workspace_root: Path) -> None:
for arg in args[1:]:
for match in re.findall(r"/[A-Za-z0-9_./-]+", arg):
for match in re.findall(r"(?<![A-Za-z0-9_.-])/[A-Za-z0-9_./-]+", arg):
candidate = Path(match).expanduser().resolve()
try:
candidate.relative_to(workspace_root)
Expand Down
21 changes: 21 additions & 0 deletions coding-agent/tests/tools/test_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,27 @@ def test_none_sandbox_blocks_absolute_path_escape(self, tmp_path: Path):
assert str(workspace).lower() in blocked_text
assert "secret" not in blocked_text

def test_none_sandbox_allows_relative_paths_with_slashes(self, tmp_path: Path):
workspace = tmp_path / "workspace"
workspace.mkdir()
pipeline_ctx = SimpleNamespace(
config={"workspace_root": str(workspace), "shell": {"sandbox_mode": "none"}}
)

mkdir_result = bash_run(
command="mkdir -p src/mini_strings tests",
cwd=str(workspace),
__pipeline_ctx__=pipeline_ctx,
)
pytest_result = bash_run(
command="python3 -m pytest tests/test_slug.py -q",
cwd=str(workspace),
__pipeline_ctx__=pipeline_ctx,
)

assert _as_text(mkdir_result) == "(no output)"
assert "outside sandbox workspace" not in _as_text(pytest_result).lower()

def test_cd_outside_workspace_is_rejected(self, tmp_path: Path):
workspace = tmp_path / "workspace"
workspace.mkdir()
Expand Down