Skip to content
Closed
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
12 changes: 12 additions & 0 deletions python/strands_agents_sops/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@ def load_external_sops(sop_directories: list[Path]) -> list[dict[str, Any]]:
description = overview_match.group(1).strip().replace("\n", " ")
sop_name = sop_file.stem.removesuffix(".sop")

# sop_name is later joined onto an output directory as a bare
# path segment (e.g. skills.py's `output_path / sop_name`) to
# create per-SOP files/directories. A crafted filename such as
# "...sop.md" derives sop_name == "..", which escapes the
# intended output directory by one level. Reject any name that
# isn't a plain, single path component.
if not sop_name or sop_name in (".", "..") or os.sep in sop_name:
logger.warning(
f"Skipping SOP with unsafe name {sop_name!r} from {sop_file}"
)
continue

external_sops.append(
{
"name": sop_name,
Expand Down
13 changes: 13 additions & 0 deletions python/tests/test_external_sop_loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,19 @@ def test_handle_nonexistent_directory(self):
sops = load_external_sops([nonexistent_path])
assert len(sops) == 0 # Should handle gracefully

def test_reject_path_traversal_sop_name(self):
"""A filename like '...sop.md' derives sop_name == '..', which would
escape the intended output directory when later joined onto one
(e.g. skills.py's `output_path / sop_name`). Must be skipped."""
with tempfile.TemporaryDirectory() as temp_dir:
sop_content = """## Overview
Attempts to masquerade as the parent directory.
"""
(Path(temp_dir) / "...sop.md").write_text(sop_content)

sops = load_external_sops([Path(temp_dir)])
assert len(sops) == 0


class TestMCPIntegration:
"""Test MCP server integration with external SOPs"""
Expand Down